not in和等价代替not exists
not in在使用中并不推荐,因为可能会出现查询错误的情况
- not in使用注意
一定要考虑追加is not null
select a.pk from a
where a.dr =0
and a.pk not in(
select b.pk from b where dr = 0 and b.pk is not null
)
2.用not exists代替
select a.pk from a
where dr = 0
and not exists(
select b.pk from b where b.pk = a.pk and dr = 0
)