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
 General SQL Server Forums
 New to SQL Server Programming
 Delete the Child Records without a Parent

Author  Topic 

StacyOW
Yak Posting Veteran

93 Posts

Posted - 2013-10-12 : 12:13:55
I am importing data from a paradox table and trying to clean it up. I have this query that finds all the child records that are not in the parent table.
Select MemberID 
FROM memtype AS a
WHERE NOT EXISTS
(SELECT *
FROM members AS b
WHERE a.MemberID IN (b.MemberID));


Now I'm trying to delete all those child records instead of just selecting them so I tried...
Delete MemberID 
FROM memtype AS a
WHERE NOT EXISTS
(SELECT *
FROM members AS b
WHERE a.MemberID IN (b.MemberID));


Sql clearly doesn't like this. What am I doing wrong?

Thanks,
Stacy

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-10-12 : 12:37:44
Delete a
FROM memtype AS a
WHERE NOT EXISTS
(SELECT *
FROM members AS b
WHERE a.MemberID IN (b.MemberID));

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -