Reputation: 267
I have two tables (Table1 and Table2.) I want to delete all rows in table2 if the id exsits in table1
Code so far:
DELETE a.id, a.car, a.boat
FROM Table2 a
LEFT JOIN Table1 b ON b.id = a.id
tables:
id, car, boat
id, car, boat
(delete if ID is same value as ID in table1)Upvotes: 0
Views: 307
Reputation: 22054
Test this in a rollback transaction first (good habit to always do this with deletes)
DELETE FROM table2
WHERE table2.id IN (SELECT table1.id FROM table1)
Upvotes: 2