由于在查询时需要找出没有被引用过的数据如下表:
A表 B表
id id
1 2
2 3
3 5
4
5
6
例如:要查询A表中没有被用过的数据(1、4、6)
select id from A where id not in (select id from B);
select id from A where not exists (select id from B);
如果表中有null,查询结果则会显示Empty set,所以要避免空值出现