我有两个表(Table1和Table2。)如果table1中的id exsits我想删除table2中的所有行
到目前为止代码:
DELETE a.id, a.car, a.boat
FROM Table2 a
LEFT JOIN Table1 b ON b.id = a.id
表:
id, car, boat
id, car, boat
(如果ID与table1中的ID相同,则删除)答案 0 :(得分:5)
Delete from table2 where table2.ID IN (select id from table1)
答案 1 :(得分:5)
DELETE Table2
FROM Table2
JOIN Table1 ON Table1.ID = Table2.ID
答案 2 :(得分:2)
首先在回滚事务中对此进行测试(总是通过删除来做这个习惯)
DELETE FROM table2
WHERE table2.id IN (SELECT table1.id FROM table1)