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
 SQL Server Development (2000)
 Need help with deletion query

Author  Topic 

KidSQL
Yak Posting Veteran

88 Posts

Posted - 2005-05-19 : 09:48:36
Don't know why I can't seem to manage this, but my mind has gone blank.

I have a table:

Date ID Value

with some 3 million records in it. I have a subset of this table (same format, Date ID Value) which I need to delete from this table. Could someone help me out with how I should do this? It's easy to: delete from mytable where date = 'whatever' but how do I perform this when I have to specify both ids and dates?

For instance, I get the correct deletion records doing:

select * from maintable a,
inner join subset b
where a.id = b.id
and a.date =b.date

but how do I use delete with this (in other words, how do I delete all the records of subset b from maintable a given Date + ID)?

Any help from a kind soul for a frustrated git would be very much appreciated.

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2005-05-19 : 10:27:04
DELETE a
FROM MainTable a INNER JOIN Subset b ON (a.ID = b.ID AND a.Date = b.Date)

Dustin Michaels
Go to Top of Page

KidSQL
Yak Posting Veteran

88 Posts

Posted - 2005-05-19 : 10:38:24
Jeez, I knew it was something simple. Thank you very much for your help.
Go to Top of Page
   

- Advertisement -