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 |
|
lkytmr
Starting Member
14 Posts |
Posted - 2002-11-19 : 10:55:29
|
| I know this is simple, but I am an infrequent user and cannot figure this one out.Table afield mywordfield other fieldsTable bfield mywordno other fieldsWant to delete all entries in table a where a.myword = b.myword.b.myword is a small subset of a.myword. For every b.myword, a.myword does exist but not the reverse.I have tried joins with a select and this works but when I substitute the word delete for select, it fails.Thanks for help.Tom Ryan |
|
|
burbakei
Yak Posting Veteran
80 Posts |
Posted - 2002-11-19 : 11:02:43
|
| DELETE TableAFROM TableBWHERE TableA.myword = TableB.myword |
 |
|
|
lkytmr
Starting Member
14 Posts |
Posted - 2002-11-19 : 13:00:26
|
| I don't follow.The tables are defined as 'a' and 'b'. Do you mean "Delete a from b where a.myword = b.myword"or "Delete a.myword from b where a.myword=b.myword"or "Delete a.myword from b.myword where a.myword=b.myword"It seems to me that a simple "Delete * from a where a.myword=b.myword" should work but it doesn't. It seems to want to treat b.myword as a parameter.What do you think? |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-11-19 : 13:06:40
|
| >> Delete * from a where a.myword=b.mywordyou need to tell it you are going to access b sodelete a from b where a.myword=b.mywordor you can code itdelete from a from b where a.myword=b.mywordbut not delete * from...look at the syntax for delete in the bol.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-11-19 : 13:08:37
|
| Needs a little tweaking:DELETE TableA FROM TableA INNER JOIN TableB ON TableA.myword = TableB.mywordThe syntax for DELETE...FROM is fully detailed in Books Online. You could also use the WHERE syntax as before, but it's probably better to use the INNER JOIN syntax. |
 |
|
|
|
|
|