I have Table T1 with Column C1,C2 and Table T2 with Column C3,C4,C5. I would like delete records from T1 where C1 = C3 AND C2 = C4 and C5 = '123'. What will be the query I tried following
DELETE FROM T1 WHERE (C1,C2) = SELECT (C3,C4) FROM T2 WHERE C5 = '123'
but this is not working.
A DELETE statement can include JOIN operations. It can contain zero, one, or multiple JOIN operations. The DELETE removes records that satisfy the JOIN conditions.
There is no WHERE (x,y) = (a,b)
syntax in SQL Server, sorry. This is how you perform a delete, based on a join, regardless of how many columns are involved in the join:
DELETE t1
FROM t1
INNER JOIN t2
ON t1.c1 = t2.c3
AND t1.c2 = t2.c4
WHERE t2.c5 = '123';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With