3
- ID
- 名称
表2:
- ID
- other_table_id
- table_1_id
- ..
基本上就是我想要做的就是
Delete from table_1
where id not in (select table_1_id
from table_2
group by table_1_id);
这应该工作,我想知道是如果子查询做到这一点的最好办法/是有没有其他办法?
表2:
基本上就是我想要做的就是
Delete from table_1
where id not in (select table_1_id
from table_2
group by table_1_id);
这应该工作,我想知道是如果子查询做到这一点的最好办法/是有没有其他办法?
我宁愿使用JOIN
而不是子查询。
DELETE a FROM table_a a
LEFT JOIN table_2 b
ON a.ID = b.table_1_id
WHERE b.table_1_id IS NULL
需要预订标记SQLFiddle。总是忘记它。 –