文章详情页
mysql - 下面语句用left join 还是用not in?
浏览:129日期: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. boot2docker无法启动2. webpack - vue-cli写的项目(本地跑没有问题),准备放到Nginx服务器上,有什么配置需要改的?还有怎么部署?3. javascript - iview 打包之后 找不到自带的icon图片,而且路径重复,点解4. 问题Unknown column ’’ in ’where clause’5. javascript - 哪位大神指导下,如何实现今日头条头部导航列表,点那个类型,哪种类型就居中了?6. 微信公众号发送模板消息返回错误410007. 这是什么情况???8. redis存储微博点赞的人,如何存储?9. html - 为什么我给div设置display:inline然后设置height还是有效呢10. media-query - 请教为何CSS3媒体查询语法不能生效?
排行榜
