SammyG
asked on
Help finding orphaned records...
I 2 Tables:
AdapterFeed and AdapterProperty
AdapterFeed has a pk of AdapterFeedID. This forms the fk for AdapterProperty.
I would like to delete all the records from AdapterProperty that don't have related records in AdapterFeed.
?
AdapterFeed and AdapterProperty
AdapterFeed has a pk of AdapterFeedID. This forms the fk for AdapterProperty.
I would like to delete all the records from AdapterProperty that don't have related records in AdapterFeed.
?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
delete from b where aa not in (select aa from a);
delete from b where not exists (select 1 from a where a.aa=b.aa);
delete from b where not exists (select 1 from a where a.aa=b.aa);
It could be done on SQL Server like this. Oracle wouldn't accept this query, so in that case you'll have to use irinaq's suggestion. (Don't know about other db's)
DELETE A.*
FROM A LEFT JOIN B ON A.pk = B.fk
WHERE B.fk Is Null
DELETE A.*
FROM A LEFT JOIN B ON A.pk = B.fk
WHERE B.fk Is Null
ASKER
Thanks, is there no way to use joins?
Sorry to say, but it seems you're caught in a loop.
I clearly used a join (FROM A LEFT JOIN B ), i can't join them any more
I clearly used a join (FROM A LEFT JOIN B ), i can't join them any more
ASKER