文章详情页
mysql - 下面语句用left join 还是用not in?
浏览:128日期: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. html - 爬虫时出现“DNS lookup failed”,打开网页却没问题,这是什么情况?2. javascript - echart+百度地图3. 无效的配置对象已使用与API模式不匹配的配置对象初始化了Webpack4. web - Rails3使用form_for时出现undefined method `*_path’错误。5. css - autoprefixer没有添加web-kit前缀6. javascript 开发百度地图7. nginx - 关于vue项目部署到ngnix后出现的问题8. angular.js - 百度爬虫如何处理“#”符号?9. nosql - mongodb 多组数据不固定字段查询问题 [百度党请绕道]10. font-family - 我引入CSS3自定义字体没有效果?
排行榜
