A表:
id字段 aid字段
10000 99999
10000 88888
10001 77777
10001 66666
B表:
did字段
77777
有以上两张表,A表id字段对应多个aid字段。要查询出来A表id字段,并且对应的所有aid字段都不在B表中。以上情况要求查询出10000。
求大神指点,谢谢。
select id from A where id not in(select t.id from A t,B s where t.aid in(select did where b));哈哈,不知道对不对...
select distinct A.id from A
where not exist
(select * from A as A2 inner join B on a.aid = B.did and A.id = A2.id)