求助:一个sql的写法,可能是很常见的,但是不知道如何修改
我有个需求是这样的:
A B两个表
A和B是一对多外键关系
A的主键是aid同时也是B的外键,B的主键是bid
我现在要取A表中没有在B表出现
我的 sql是:
第一种
select a.aid
from A a
where a.aid not in (select aid from B)
这个因为A B表数量大,太慢。
第二种
select a.aid
from A a,B b
where A.aid=B.aid(+)
and B.bid is null
这个好像倒是挺快的,但是我不确定对不。
第三种
select a.aid
from A a
where a.aid not in (select aid from B where aid=a.aid)
高手指点下。数据量比较大。不知道该怎么写才好呀。
第二种不确定是不是正确呀。查的结果是一样的。