文章詳情頁
mysql - 下面語句用left join 還是用not in?
瀏覽:114日期:2022-06-11 16:23:39
問題描述
實現:查詢a中沒有關聯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的區別
相關文章:
1. Docker for Mac 創建的dnsmasq容器連不上/不工作的問題2. javascript - QWebEngineView 如何爬 angular 的動態數據?3. javascript - 使用angular 的ui-sref 中出現了中文參數,點擊跳轉后瀏覽器的地址欄里出現轉義后的%AE....%a%44. java - ConcurrentHashMap中的get()方法為什么可以不加鎖?5. java - 郵箱如何發送html內容6. html5 - 這個代碼顯示功能如何實現?7. javascript - 用JS 七牛上傳圖片出現文件已存在的錯誤(file exists)8. 工作近5年,3年Java Web ,近2年前端,未來何去何從?9. css3 - 圖片等比例縮放10. java - 字節流轉成字符串之后,在通過字符串轉成字節流后的文件為什么會不一樣?
排行榜
