mysql - Should I use left join or not in in the following statement?
PHP中文网
PHP中文网 2017-06-06 09:52:24
0
2
1063

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

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
小葫芦

not existsCorrect answer

select id from a where not exists (select 1 from b where a.id=b.aid) and status = 1
習慣沉默

I want to use not exists

A brief discussion on the difference between in and not in, exists and not exists in sql

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template