文章詳情頁
mysql - 下面語句用left join 還是用not in?
瀏覽:96日期:2022-06-11 16:23:39
問題描述
實(shí)現(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
那種更好,或者有其他的方式,請(qǐng)大神留下答案
問題解答
回答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. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過段時(shí)間會(huì)消失是什么情況?2. javascript - 在 vue里面用import引入js文件,結(jié)果為undefined3. python沒入門,請(qǐng)教一個(gè)問題4. php如何獲取訪問者路由器的mac地址5. html5 - input type=’file’ 上傳獲取的fileList對(duì)象怎么存儲(chǔ)于瀏覽器?6. 小程序怎么加外鏈,語句怎么寫!求救新手,開文檔沒發(fā)現(xiàn)7. 求教一個(gè)mysql建表分組索引問題8. node.js - 用nodejs 的node-xlsx模塊去讀取excel中的數(shù)據(jù),可是讀取出來的日期是數(shù)字,請(qǐng)問該如何讀取日期呢?9. sql語句如何按or排序取出記錄10. javascript - vue-resource中如何設(shè)置全局的timeout?
排行榜

熱門標(biāo)簽