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)
 Join 2 table in Not Exists

Author  Topic 

melon.melon
Yak Posting Veteran

76 Posts

Posted - 2009-06-18 : 05:23:58
I want to delete from tbCost1 if "no" is not found in tbCost2 & tbCost3 :

Delete from tbCost1 where Not EXISTS (select * from tbCost2 a Inner Join tbCost3 b where a.no='222' and b.no='222') and no='222'

raky
Aged Yak Warrior

767 Posts

Posted - 2009-06-18 : 05:40:45
try this

Delete t1
from tbCost1 t1
left join tbcost2 t2 on t2.no = t1.no
left join tbcost3 t3 on t3.no = t1.no
where t1.no= '222'
and t2.no is null and t3.no is null
Go to Top of Page

melon.melon
Yak Posting Veteran

76 Posts

Posted - 2009-06-18 : 06:10:28
Incorrect syntax near 'a'.

Delete from t1 a left join t2 b on t2.no=t1.no
left join t3 c on t3.no=t1.no where a.no='222'
and b.no is null and c.no is null
Go to Top of Page

melon.melon
Yak Posting Veteran

76 Posts

Posted - 2009-06-18 : 21:49:42
Thanks for your help, was my mistake i didnt understand that i need to put in that part so i left it out.
[/quote]
Delete t1
from tbCost1 t1
[/quote]


Go to Top of Page
   

- Advertisement -