sql三表查询找出没有写入中间表的记录

2025-02-22 13:56:04
推荐回答(2个)
回答1:

A表在B,C表中都没有进行关联的ID
select id from A
where id not exisets (select id from (select id from B union select id from C) test);

A表没有在B,C表中同时进行关联的ID
select id from A
where id not exisets (select B.id from B inner join C on B.id=C.id);

补充:根据你的补充的补充
select id from A whre id not in (select id from B);
或者
select id from A whre id not exists (select id from B);

回答2:

C表进行关联的A表id :
select t1.name,t2.name from c t1
inner join a t2 on t2.id =t1.id

A表中没有在B表中:
select * from b t1
inner join a t2 on t2.id =t1.id