0

我有 2 张桌子。

我如何知道一个表中而不是另一表中的 ID?我将如何做到这一点?

然后我想删除所有这些 ID。

4

3 回答 3

3

这很简单:

delete from t1
using table1 as t1
left outer join table2 as t2
on t1.id = t2.id
where t2.id is null

值得注意的是,连接比子查询快。

于 2012-07-02T03:45:17.163 回答
3

使用此查询:

 delete from TABLE_A where ID not in (select ID from TABLE_B)
于 2012-07-02T03:45:38.917 回答
1

使用此查询:

delete from t1 
where id not in
(select t2.id from t2)
于 2012-07-02T03:47:14.773 回答