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)
 Delete with inner join

Author  Topic 

tracy5436
Yak Posting Veteran

50 Posts

Posted - 2010-09-17 : 12:23:48
Hi,

I am trying to delete records in the sop10200 table which are related to those in the sop10100 for a particular batch numberonly. The two tables are joined by the sopnumbe field. I have used the following query :

delete sop10200
WHERE exists (select * from sop10100 inner join sop10200 on sop10200.sopnumbe = sop10100.sopnumbe Where bachnumb = 't11')


However, when I run it, it deletes all records in the sop10200 table.

What am I doing wrong ?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-17 : 12:25:36
it should be

delete s from sop10200 s
WHERE exists (select 1 from sop10100 where sopnumbe = s.sopnumbe and bachnumb = 't11')


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

Go to Top of Page
   

- Advertisement -