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 2005 Forums
 Transact-SQL (2005)
 Need a Delete statement from two tables

Author  Topic 

CLEE25
Starting Member

14 Posts

Posted - 2008-12-11 : 20:43:02
Hey all,

I have two tables

Temp (ID, Name)
Solid (ID, Name)

What I am looking to do is update the Solid Table from the temp table--which I have already done.

What I want to do next is delete the records in the Temp Table that have been updated. Ie, I want to delete the records in the Temp Table where the Temp.ID=Solid.ID

Then I plan to import what is left in the temp table (those records without a matching ID) as new records in the Solid Table.

Can anyone give a statement? Something like

Delete from Temp where (Temp.ID=Solid.ID)

Thanks for any help!

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2008-12-11 : 23:01:16
create table temp(id int ,name varchar(32))

insert into temp select 1,'kk'

create table temp1(id int ,name varchar(32))

insert into temp1 select 1,'sdf'

delete temp where temp.id in (select id from temp1)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-11 : 23:23:08
or use join
DELETE t FROM Temp t JOIN Solid s ON s.ID=t.ID
Go to Top of Page

CLEE25
Starting Member

14 Posts

Posted - 2008-12-12 : 11:55:56
Thanks so much all!

visakh16 the code worked perfect.

I owe you!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-13 : 00:38:11
no problem... you're welcome
Go to Top of Page
   

- Advertisement -