SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 where x and y are in a select
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pavlos
Yak Posting Veteran

Greece
58 Posts

Posted - 05/27/2012 :  20:19:08  Show Profile  Reply with Quote
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

Greece
58 Posts

Posted - 05/27/2012 :  20:22:55  Show Profile  Reply with Quote
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

India
47035 Posts

Posted - 05/27/2012 :  21:48:31  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000