Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Tricky Query

Author  Topic 

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2005-09-07 : 18:53:47
I have three tables,
1. Imports (field of XNumber)
2. General Info (fields of XNumber, YNumber)
3. Milestones (field of YNumber)

and what I need to do is delete records from the Milestones table where the Imports key/field doesn't match. So, basically delete all unmatched records in Milestones where there's no match with Imports.

The problem is that I've got to use General Info as a join, or parent table.
The schema looks like (at least I'm trying this way):
GeneralInfo.YNumber TO Milestones.YNumber
GeneralInfo.XNumber TO Imports.XNumber

YNumber in the GeneralInfo table is the unique identifer, and I do have this to work with on a select or delete statement.

There can be multiple same YNumbers in Milestones, and multiple same XNumbers in Imports.

Kristen
Test

22859 Posts

Posted - 2005-09-08 : 06:59:00
I'd start with a framework like this, and then when the right data is being selected comment in the DELETE clause

SELECT *
-- DELETE I
FROM GeneralInfo AS GI
JOIN Milestones AS M
ON M.YNumber = GI.YNumber
JOIN Imports AS I
ON I.XNumber = GI.XNumber
WHERE ...

Kristen
Go to Top of Page

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2005-09-09 : 09:38:17
Thanks!

I pretty much had to do a subquery in the where clause.
Go to Top of Page
   

- Advertisement -