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 2008 Forums
 Transact-SQL (2008)
 Need to put some filter in Delete query

Author  Topic 

shantanu88d
Starting Member

35 Posts

Posted - 2011-05-02 : 07:01:09
Hi I have 2 tables
1. mobile_brands
2. mobile_master

master table contains purchase entry of all mobiles in systm. first table is just a stand alone table having all brand names
i want to create a delete query which will delete a brand_name from mobile_brands only if that value does not exist in mobile_master table. How to go on about this query ???

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-05-02 : 07:04:20
delete mb
from mobile_brands mb
where not exists(select * from mobile_master mm where mm.brand_name = mb.brand_name)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-05-02 : 07:05:03
DELETE FROM mobile_brands
WHERE brand_name NOT IN
(SELECT brand_name FROM mobile_master)

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page
   

- Advertisement -