查看“什么时候用 in ?什么时候用 exists ?”的源代码
←
什么时候用 in ?什么时候用 exists ?
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看和复制此页面的源代码。
=== 示例 === <syntaxhighlight lang="sql"> select name from employees where empno in (select distinct empno from job_history); </syntaxhighlight><syntaxhighlight lang="sql"> select name from employees where exists (select empno from job_history where employees.empno=job_history.empno); </syntaxhighlight>如果 employees 中记录数大于 job_history 时,用 in 效率高。 如果 employees 中记录数小于 job_history 时,用 exists 效率高。 注意:在星辰项目遇到过1次关于in的奇怪问题,查询语句的结构比较复杂,但总的来说问题是使用了多重子查询后,in条件失效,没有通过in条件中的子查询把应该筛选出来的数据筛选出来。 以后尽量少用in查询吧,感觉简单的查询、in 中只有比较少的值的时候使用 in 还比较可靠,否则如果 in 里的值是其它子查询的结果还是用连接查询代替吧
返回至
什么时候用 in ?什么时候用 exists ?
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
Spring Boot 2 零基础入门
Spring Cloud
Spring Boot
设计模式之禅
VUE
Vuex
Maven
算法
技能树
Wireshark
IntelliJ IDEA
ElasticSearch
VirtualBox
软考
正则表达式
程序员精讲
软件设计师精讲
初级程序员 历年真题
C
SQL
Java
FFmpeg
Redis
Kafka
MySQL
Spring
Docker
JMeter
Apache
Linux
Windows
Git
ZooKeeper
设计模式
Python
MyBatis
软件
数学
PHP
IntelliJ IDEA
CS基础知识
网络
项目
未分类
MediaWiki
镜像
问题
健身
国债
英语
烹饪
常见术语
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息