文章詳情頁
mysql - 下面語句用left join 還是用not in?
瀏覽:102日期: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. mac OSX10.12.4 (16E195)下Mysql 5.7.18找不到配置文件my.cnf2. mysql - 數據庫表中,兩個表互為外鍵參考如何解決3. 在mybatis使用mysql的ON DUPLICATE KEY UPDATE語法實現存在即更新應該使用哪個標簽?4. mysql - 數據庫建字段,默認值空和empty string有什么區別 1105. mysql儲存json錯誤6. sql語句 - 如何在mysql中批量添加用戶?7. mysql - 表名稱前綴到底有啥用?8. php - 公眾號文章底部的小程序二維碼如何統計?9. Navicat for mysql 中以json格式儲存的數據存在大量反斜杠,如何去除?10. mysql - 怎么生成這個sql表?
排行榜
