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 |
|
sahu74
Posting Yak Master
100 Posts |
Posted - 2004-02-27 : 16:28:57
|
| I know this might sound silly but I cannot think of a way to delete some records from a table.I have some records in a temp table #ABC with fields say F2,F3,F4 which I get from a select query.I want to delete all records from table XYZ (with following fields F1,F2,F3,F4) that have records matching in #ABC on F2,F3 and F4.Any help will be greatly appreciated.Thank you.PKS. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-02-27 : 16:35:46
|
| DELETE XYZFROM XYZ t1INNER JOIN #ABC t2 ON t1.F1 = t2.F1 AND t1.F2 = t2.F2...Tara |
 |
|
|
ilimax
Posting Yak Master
164 Posts |
Posted - 2004-02-27 : 22:30:43
|
| I always use this one and works beautifull...DELETE * FROM Table1WHERE (((Table1.[Loan ID]) In (SELECT [Loan ID] FROM [Table2]))); |
 |
|
|
sahu74
Posting Yak Master
100 Posts |
Posted - 2004-02-29 : 01:43:40
|
| Thank you Tara. You made it look so simple. I am feeling a lil embarrased now for not thinking of that. I am not sure if ilimax's code would work for multiple fields. Any comments ???Thanks again.PKS. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-03-01 : 12:16:59
|
| You could use it for multiple fields, but the JOIN syntax is the way to go.Tara |
 |
|
|
smousumi
Starting Member
19 Posts |
Posted - 2004-03-02 : 06:58:21
|
| Its Quite simple and i think it will solve ur problem...DELETE XYZ FROM XYZ A1 INNER JOIN #ABC A2 ON (A1.F2=A2.F2 AND A1.F3=A2.F3 AND A1.F4=A2.F4)mousumi |
 |
|
|
|
|
|