文章詳情頁
mysql - 下面語句用left join 還是用not in?
瀏覽:76日期: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)文章:
1. docker-machine添加一個已有的docker主機(jī)問題2. golang - 用IDE看docker源碼時的小問題3. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?4. docker網(wǎng)絡(luò)端口映射,沒有方便點(diǎn)的操作方法么?5. docker - 如何修改運(yùn)行中容器的配置6. debian - docker依賴的aufs-tools源碼哪里可以找到啊?7. docker綁定了nginx端口 外部訪問不到8. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個是怎么回事????9. docker-compose中volumes的問題10. node.js - nodejs debug問題
排行榜

熱門標(biāo)簽