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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 delete confusion

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 XYZ
FROM XYZ t1
INNER JOIN #ABC t2 ON t1.F1 = t2.F1 AND t1.F2 = t2.F2...

Tara
Go to Top of Page

ilimax
Posting Yak Master

164 Posts

Posted - 2004-02-27 : 22:30:43
I always use this one and works beautifull...


DELETE * FROM Table1
WHERE (((Table1.[Loan ID]) In (SELECT [Loan ID] FROM [Table2])));
Go to Top of Page

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.
Go to Top of Page

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
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -