我有 2 张桌子。
我如何知道一个表中而不是另一表中的 ID?我将如何做到这一点?
然后我想删除所有这些 ID。
这很简单:
delete from t1
using table1 as t1
left outer join table2 as t2
on t1.id = t2.id
where t2.id is null
值得注意的是,连接比子查询快。
使用此查询:
delete from TABLE_A where ID not in (select ID from TABLE_B)
使用此查询:
delete from t1
where id not in
(select t2.id from t2)