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 question

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2010-09-30 : 04:59:30
Hi,

I have this simple query

SELECT a.* FROM tblPricing a
INNER JOIN tblBannedIDs b
ON a.id = b.id AND a.[type] = b.[type]

What I need to do instead on selecting these rows is to delete them from tblPricing. How can I do that?

If only one column was involved I know I could do DELETE FROM tblPricing WHERE id IN (SELECT id FROM tblBannedIDs) but not sure with there being 2 columns needed to filter.

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-09-30 : 05:17:42
[code]DELETE tgt
FROM tblPricing AS tgt
INNER JOIN tblBannedIDs AS src ON src.ID = tgt.ID
AND src.[Type] = tgt.[Type]

DELETE tblPricing
WHERE EXISTS (SELECT * FROM tblBannedIDs AS x WHERE x.ID = ID AND x.[Type] = [Type])[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -