I've been really reluctant to post this because I feel it's a common issue, but I can not seem to find an answer that applies to this situation... (maybe I'm just a really bad googler).
I have two identical tables(column wise, not data), table1 and table2. I wish to delete the records in table1 in which the composite key (col1, col2) exists in both tables. Here is what I have, which seems correct to me, but is throwing an error.
DELETE FROM Table1
WHERE (**Col1**, Col2) IN
(SELECT Col1, Col2
FROM Table1 a
JOIN Table2 b
ON a.Col1 = b.Col1
AND a.Col2 = b.Col2)
Error:
Msg 4145, Level 15, State 1, Line 212 An expression of non-boolean type specified in a context where a condition is expected, near ','.
I have put two *
around the portion of code which has 'Red error squiggles'.
This can be cleanly performed using JOIN
with your DELETE
:
DELETE a
FROM
Table1 a
JOIN Table2 b
ON a.Col1 = b.Col1
AND a.Col2 = b.Col2
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