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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Delete the Child Records without a Parent
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

StacyOW
Yak Posting Veteran

USA
93 Posts

Posted - 10/12/2013 :  12:13:55  Show Profile  Reply with Quote
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

India
22864 Posts

Posted - 10/12/2013 :  12:37:44  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000