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 |
|
RichardSteele
Posting Yak Master
160 Posts |
Posted - 2004-01-11 : 04:33:26
|
| I have two tables: stock_local and stock_remote. I need to delete any records in stock_remote that are no longer in stock_local. The key field that relates the two is catnum. What would the delete statement look like that would do this job?Many thanks. |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2004-01-11 : 05:18:35
|
| DELETE FROM stock_remoteWHERE catnum NOT IN (SELECT catnum FROM stock_local)Damian |
 |
|
|
RichardSteele
Posting Yak Master
160 Posts |
Posted - 2004-01-11 : 19:09:05
|
| Thanks!Now what would the code look like if I want to delete those records where the number is found but the stock_remote.xflag is not the same as stock_local.xflag?Many thanks in advance. |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-01-11 : 20:04:40
|
| delete from stock_remote from stock_remote t2 left join stock_local t1on t2.catnum=t1.catnum and t2.xflag=t1.xflagwhere t1.catnum is null |
 |
|
|
|
|
|