select * from a where a.id not in(select A.a.id from a A,b B,c C,d D where A.a.id=B.a.id and A.a.id=C.a.id and A.a.id=D.a.id)
select a.id from a where a.id not in(select b.id from b union select c.id from c union select d.id from d)
将b,c,d表的ID 并在一起,a和并集left join就行了,伪代码如下
select * from a left join ( b unionl c union l d ) u on a.id=u.id where u.id is null
光阴的方法可行。
SELECT *
FROM a
WHERE a.id NOT IN (
SELECT B.id FROM b B
UNION
SELECT C.id FROM c C
UNION
SELECT D.id FROM d D
)
PS:UNION表示并集,NOT IN 后面,括号内的SQL语句表示,b,c,d三个表中所有a.id的并集。
select * from a where id not in(select id from b union select id from c union select id from d)
sql 可以直接用
select * from b where not exists (select 1 from (select id from a where a.id=b.id))
select * from c where not exists (select 1 from (select id from a where a.id=c.id))
select * from d where not exists (select 1 from (select id from a where a.id=d.id))
找到三个表里面 A表里面都不存在的id 然后把这些ID整合 找出相同的 出来 就能查询出来
a表的id 在b c d中都不存在的a.id的数据
select a.id from a where a.id not in(
select distinct e.id from (select b.id from b union select c.id from c union select d.id from d ) as e)