Implementation: Query records in a that are not associated with b
1、select id from a left join b on a.id = b.aid where b.id is null and status = 1
2、select id from a where id not in (select aid from b) and status = 1
Which one is better, or if there is another way, please leave the answer
高洛峰2017-06-06 09:54:24
not existsCorrect answer
select id from a where not exists (select 1 from b where a.id=b.aid) and status = 1
習慣沉默2017-06-06 09:54:24
I want to use not exists
A brief discussion on the difference between in and not in, exists and not exists in sql