成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

mysql - 下面語句用left join 還是用not in?

瀏覽:108日期:2022-06-11 16:23:39

問題描述

實現(xiàn):查詢a中沒有關(guān)聯(lián)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

那種更好,或者有其他的方式,請大神留下答案

問題解答

回答1:

not exists正解

select id from a where not exists (select 1 from b where a.id=b.aid) and status = 1回答2:

我想使用 not exists

淺談sql中的in與not in,exists與not exists的區(qū)別

相關(guān)文章: