Delete all rows in a table based on another table

Viewed 253632

I can't seem to ever remember this query!

I want to delete all rows in table1 whose ID's are the same as in Table2.

So:

DELETE table1 t1
 WHERE t1.ID = t2.ID

I know I can do a WHERE ID IN (SELECT ID FROM table2) but I want to do this query using a JOIN if possible.

15 Answers
delete
    table1
from 
    t2
where
    table1.ID=t2.ID

Works on mssql

Related