Link to home
Start Free TrialLog in
Avatar of SammyG
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.

?
ASKER CERTIFIED SOLUTION
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SammyG
SammyG

ASKER

Thanks, is there no way to use joins?
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);
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
Avatar of SammyG

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