Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Tricky Query

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.
[841 byte] By [bubberz] at [2007-11-11 6:47:37]
# 1 Re: Tricky Query
Try something like :-

delete from Milestones
where YNumber not in (
select YNumber from General Info
inner join Imports
on General Info.XNumber = Imports.XNumber)
DeeplyDippy at 2007-11-11 23:48:06 >