文章詳情頁
mysql - 下面語句用left join 還是用not in?
瀏覽:104日期: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. css - C#與java開發Windows程序哪個好?2. mysql無法添加外鍵3. css - 定位為absolute的父元素中的子元素 如何設置在父元素的下面?4. java - Mybatis查詢數據庫時出現查詢getInt()的錯誤5. JavaScript事件6. javascript - 原生canvas中如何獲取到觸摸事件的canvas內坐標?7. javascript - es6將類數組轉化成數組的問題8. 在mac下出現了兩個docker環境9. css3 - flex 父標簽設置align-item:center,子元素flex:1,不起作用10. java - 是否類 類型指針、引用作為形參 ,函數結束不會自動析構類?
排行榜
