数据库查询时,in用exists代替例子
来源:互联网 发布:js将字符串转换为json 编辑:程序博客网 时间:2024/06/06 04:54
现有一张unit表,一张information表。
unit表中有name字段。
information表中有unit_name字段,来自unit表中name字段。
其中information表中,可能存在多个有同一个unit_name的数据。
现在需要查询unit表中,在information表中有的unit_name,是否存在重复的数据。
select name,count(*) from unit u where u.name in (select unit_name from information i where i.unit_name = u.name)group by u.name having count(*) > 1
修改后
select name,count(*) from unit u where exists (select * from information i where i.unit_name = u.name)group by name having count(*) > 1
这样查询的时候效率更高。
0 0
- 数据库查询时,in用exists代替例子
- 查询速度优化用not EXISTS 代替 not in
- 写sql 用EXISTS 代替 in
- IN、EXISTS的相关子查询用INNER JOIN 代替--sql2000性能优化
- IN的相关子查询用EXISTS代替--sql2000性能优化
- 数据库查询优化之用exists替换in,not exists替换not in
- 使用exists+使用exists代替in+使用exists代替distinct
- EXISTS 代替 in ,not EXISTS 代替 not in
- 用exists代替max
- 用exists代替distinct
- exists和not exists用法 代替in和not in
- exists和not exists用法 代替in和not in
- exists in 联合查询
- 使用 EXISTS 代替 IN 和 inner join
- 数据库 - in 和exists
- 数据库 - in 和exists
- 数据库 - in 和exists
- 数据库查询 WHERE EXISTS
- 团体程序设计天梯赛-练习集 L2-016. 愿天下有情人都是失散多年的兄妹 解题报告
- 归并排序
- webuploader上传遇到的问题
- CCF2014-03-3命令行选项
- adapter.notifyDataSetChanged()失效解决方案
- 数据库查询时,in用exists代替例子
- ajax学习笔记
- 160. Intersection of Two Linked Lists
- python 迭代器与生成器 详解
- JAVA常用类库之String类
- Java HashMap的工作原理
- mysql优化
- 机器学习之无监督聚类问题
- 【优化改进】Linux进程文件瘦身——Linux环境验证 form http://sammor.iteye.com/blog/2147762