SQL EXISTS 与 IN
EXISTS用于检查子查询是否至少会返回一行数据,该子查询实际上并不返回任何数据,而是返回值True或False
EXISTS 指定一个子查询,检测行的存在。
EXISTS与IN的使用效率的问题,通常情况下采用exists要比in效率高,因为IN不走索引,但要看实际情况具体使用:
IN适合于外表大而内表小的情况;EXISTS适合于外表小而内表大的情况。
实例:(EXISTS)
select * from dbo.PurchaseSettleAccountsDetails d where exists(select * from dbo.PurchaseSettleAccounts where ApprovalStatus=1 and ID=d.PurchaseSettleAccountId)
(IN)
select * from dbo.PurchaseSettleAccountsDetails d where PurchaseSettleAccountId IN (select ID from dbo.PurchaseSettleAccounts where ApprovalStatus=1 and ID=d.PurchaseSettleAccountId)
SQL EXISTS 与 IN的更多相关文章
- SQL EXISTS
一直对exists的用法不清楚,本次学习exists,并作出相应学习总结. 1.创造测试环境SYS@ora122>create table a(id )); SYS@ora122>inse ...
- LINQ系列:LINQ to SQL Exists/In/Any/All/Contains
1. Any 返回没有Product的Category var expr = from c in context.Categories where !c.Products.Any() select c ...
- SQL exists( select 1 from
use UnlockIndustry select * from Info_Coordinate as A join Info_Employee on A.EmployeeId=Info_Employ ...
- SQL Exists 的用法 转载
比如在Northwind数据库中 有一个查询为 SELECT c.CustomerId, CompanyName FROM Customers c WHERE EXISTS( SELECT O ...
- 浅谈sql中的in与not in,exists与not exists的区别
转 浅谈sql中的in与not in,exists与not exists的区别 12月12日北京OSC源创会 —— 开源技术的年终盛典 » sql exists in 1.in和exists ...
- 数据库——SQL中EXISTS怎么用2(转)
数据库sql语句的exists总结 sql exists in 学习 先来比较下语法: --deals=交易表,areas=地域表,例如香港:我们的目的:查看有交易的地域 select * from ...
- sql中exists和notexists用法总结(并和in的比较)
首先头脑中有三点概念: 1.EXISTS子查询找到的提交 NOT EXISTS 子查询中 找不到的提交 说明:不要去翻译为存在和不存在,把脑袋搞晕. 2.建立程序循环的概念,这是一个动态的查询过程.如 ...
- 小表驱动大表, 兼论exists和in
给出两个表,A和B,A和B表的数据量, 当A小于B时,用exists select * from A where exists (select * from B where A.id=B.id) ex ...
- Stream Processing 101: From SQL to Streaming SQL in 10 Minutes
转自:https://wso2.com/library/articles/2018/02/stream-processing-101-from-sql-to-streaming-sql-in-ten- ...
随机推荐
- [luoguP3332] [ZJOI2013]K大数查询(树套树)
传送门 一开始想的是区间线段树套权值线段树,结果好像不能实现. 然后题解是权值线段树套区间线段树. 区间线段树上标记永久化就省去了pushdown的操作减少常数. 标记永久化的话..yy不出来就看代码 ...
- JAVA简易的注册会员系统
public class Login { public static void main(String[] args) { System.out.println("*****欢迎进入注册系统 ...
- Ubuntu 硬盘大小扩展
注:途中所有图均为配置好补的截图,部分来自其它网页. 1.选择硬盘(SCSI) 2.点击扩展,在弹出框填写期望的硬盘大小(不能比原硬盘大小容量小) 3.进入虚拟机,安装GParted. 命令:sudo ...
- 【10】【转】node 之 pipe机制----未理解
转载地址:http://blog.csdn.net/vieri_32/article/details/48376547 前言 前几天别人请教我关于pipe的问题,我发现我虽然用了nodejs很久,但是 ...
- about coroutine
co 有协作的意思,是让多个 routine 合作来完成某件或者某几件事情,它主要解决的问题就是合理安排一些耗时长的工作的执行时间,让其他的工作有机会得到执行.
- Xcode打包和生成ipa文件
1.生成Archive文档 a) 需将左上角红色方框里的设备类型选为ios device,不能选择具体的设备类型,否则不能生成Archive文档: b) 中部选择Team的方框,可此时选,也在后续ex ...
- FormatDateTime 当前时间减去几小时的做法
top_start_modified := FormatDateTime('yyyy-mm-dd hh:mm:ss',(Now - ((1/24)*3))); top_end_modified ...
- hdu 1215(因子和)
七夕节 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- [Machine Learning with Python] Data Preparation by Pandas and Scikit-Learn
In this article, we dicuss some main steps in data preparation. Drop Labels Firstly, we drop labels ...
- HDU——最大连续子序列(区间DP)
上一个题的加强版! 最大连续子序列 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...