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.
| Author |
Topic |
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2011-03-10 : 14:20:20
|
| I have two tables (1)CustomerInfo and (2)RetainCustInfoThe above tables could be joined based on Custid columnI want to delete everything in the CustomerInfo table if there are no matches of Custid in the RetainCustInfo TableThanks |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-03-10 : 14:38:41
|
| DELETE FROM CustomerInfo ciWHERE NOT EXISTS(select * from RetainCustInfo rci where ci.custid = rci.custid)JimObviously make this a select statement first to ensure it works!Everyday I learn something that somebody else already knew |
 |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2011-03-10 : 14:42:20
|
Thanks JimWhy on Earth did i not think of Sub Queries.I keep reading books to learn SQL but never get ideas when I need themquote: Originally posted by jimf DELETE FROM CustomerInfo ciWHERE NOT EXISTS(select * from RetainCustInfo rci where ci.custid = rci.custid)JimObviously make this a select statement first to ensure it works!Everyday I learn something that somebody else already knew
|
 |
|
|
|
|
|