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
 General SQL Server Forums
 New to SQL Server Programming
 where x and y are in a select

Author  Topic 

pavlos
Yak Posting Veteran

59 Posts

Posted - 2012-05-27 : 20:19:08
Hey guys,
I want to delete data from a table where it exists in another table.
I have a budget table and a data table. I want to delete the rows of the data table where they exist in the budget table.

The data and budget table consists off date, storecode, value.

I have tried this
delete from data
where date in (select date from budget)
and storecode in (select storecode from budget)

but this deletes all dates and storecodes where they exist in the budget
I want to delete the rows that have the budget and storecode together.

EG.

delete from data
where date and storecode in (select date,storcode from budget)

I cant put where clauses in the select statement.

hope this makes sense

pavlos
Yak Posting Veteran

59 Posts

Posted - 2012-05-27 : 20:22:55
ignore this guys.
worked it out
delete from data
where exists in (xxxxx)

cheers
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-27 : 21:48:31
another method is delete with inner join to other table on related fields

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -