in 和 exists 区别,not in和not exists区别

EXISTS用法及与IN的区别 阅读详情

1、in和exists

1.1

select * from A

where id in(select id from B)

以上查询使用了in语句,in()只执行一次,它查出B表中的所有id字段并缓存起来.之后,检查A表的id是否与B表中的id相等,如果相等则将A表的记录加入结果集中,直到遍历完A表的所有记录.
它的查询过程类似于以下过程

List resultSet=[];
Array A=(select * from A);
Array B=(select id from B);

for(int i=0;i<A.length;i++) {
   for(int j=0;j<B.length;j++) {
      if(A[i].id==B[j].id) {
         resultSet.add(A[i]);
         break;
      }
   }
}
return resultSet;

可以看出,当B表数据较大时不适合使用in(),因为它会B表数据全部遍历一次.
如:A表有10000条记录,B表有1000000条记录,那么最多有可能遍历10000*1000000次,效率很差.
再如:A表有10000条记录,B表有100条记录,那么最多有可能遍历10000*100次,遍历次数大大减少,效率大大提升.

结论:in()适合B表比A表数据小的情况。

-----------------------------------------------------------------------------------------------------------------------------

1.2

select a.* from A a 
where exists(select 1 from B b where a.id=b.id)

以上查询使用了exists语句,exists()会执行A.length次,它并不缓存exists()结果集,因为exists()结果集的内容并不重要,重要的是结果集中是否有记录,如果有则返回true,没有则返回false.
它的查询过程类似于以下过程

List resultSet=[];
Array A=(select * from A)

for(int i=0;i<A.length;i++) {
   if(exists(A[i].id) {    //执行select 1 from B b where b.id=a.id是否有记录返回
       resultSet.add(A[i]);
   }
}
return resultSet;

当B表比A表数据大时适合使用exists(),因为它没有那么遍历操作,只需要再执行一次查询就行.
如:A表有10000条记录,B表有1000000条记录,那么exists()会执行10000次去判断A表中的id是否与B表中的id相等.
如:A表有10000条记录,B表有100000000条记录,那么exists()还是执行10000次,因为它只执行A.length次,可见B表数据越多,越适合exists()发挥效果.
再如:A表有10000条记录,B表有100条记录,那么exists()还是执行10000次,还不如使用in()遍历10000*100次,因为in()是在内存里遍历比较,而exists()需要查询数据库,我们都知道查询数据库所消耗的性能更高,而内存比较很快.

结论:exists()适合B表比A表数据大的情况。

当A表数据与B表数据一样大时,in与exists效率差不多,可任选一个使用.


-------------------------------------------------------------------------------------------------------------------------------------

1.3

结论:
EXISTS(包括 NOT EXISTS )子句的返回值是一个BOOL值。 EXISTS内部有一个子查询语句(SELECT ... FROM...), 我将其称为EXIST的内查询语句。其内查询语句返回一个结果集。 EXISTS子句根据其内查询语句的结果集空或者非空,返回一个布尔值。

一种通俗的可以理解为:将外查询表的每一行,代入内查询作为检验,如果内查询返回的结果取非空值,则EXISTS子句返回TRUE,这一行行可作为外查询的结果行,否则不能作为结果。

分析器会先看语句的第一个词,当它发现第一个词是SELECT关键字的时候,它会跳到FROM关键字,然后通过FROM关键字找到表名并把表装入内存。接着是找WHERE关键字,如果找不到则返回到SELECT找字段解析,如果找到WHERE,则分析其中的条件,完成后再回到SELECT分析字段。最后形成一张我们要的虚表。
WHERE关键字后面的是条件表达式。条件表达式计算完成后,会有一个返回值,即非0或0,非0即为真(true),0即为假(false)。同理WHERE后面的条件也有一个返回值,真或假,来确定接下来执不执行SELECT。
分析器先找到关键字SELECT,然后跳到FROM关键字将STUDENT表导入内存,并通过指针找到第一条记录,接着找到WHERE关键字计算它的条件表达式,如果为真那么把这条记录装到一个虚表当中,指针再指向下一条记录。如果为假那么指针直接指向下一条记录,而不进行其它操作。一直检索完整个表,并把检索出来的虚拟表返回给用户。EXISTS是条件表达式的一部分,它也有一个返回值(true或false)。

在插入记录前,需要检查这条记录是否已经存在,只有当记录不存在时才执行插入操作,可以通过使用 EXISTS 条件句防止插入重复记录。
INSERT INTO TableIn (ANAME,ASEX) 
SELECT top 1 '张三', '男' FROM TableIn
WHERE not exists (select * from TableIn where TableIn.AID = 7)

EXISTS与IN的使用效率的问题,通常情况下采用exists要比in效率高,因为IN不走索引,但要看实际情况具体使用:
IN适合于外表大而内表小的情况;EXISTS适合于外表小而内表大的情况。


----------------------------------------------------------------------------------------------------------------------------------

2、not in 和not exists

select * from #t1 where c2 not in(select c2 from #t2 )

select * from #t1 where c2 not exists(select 1 from #t2 where #t2.c2=#t1.c2)

select * from #t1 where c2 not in(select c2 from #t2 where #t2.c2=#t1.c2)

第2、3两个一样?

#t2里面有空值,not in出现了不期望的结果集,存在逻辑错误。如果看一下上述两个select 语句的执行计划,也会不同,后者使用了hash_aj,所以,请尽量不要使用not in(它会调用子查询),而尽量使用not exists(它会调用关联子查询)。如果子查询中返回的任意一条记录含有空值,则查询将不返回任何记录。如果子查询字段有非空限制,这时可以使用not in,并且可以通过提示让它用hasg_aj或merge_aj连接。

如果查询语句使用了not in,那么对内外表都进行全表扫描,没有用到索引;而not exists的子查询依然能用到表上的索引。所以无论哪个表大,用not exists都比not in 要快。


SQL难点对比分析:IN 和 EXISTS 的用法对比 阅读详情

相关推荐

EXISTS 和 IN 区别

EXISTS用于判断子查询是否返回至少一行数据,一旦找到符合条件的行就停止查询,适用于检查数据是否存在的场景,尤其是在子查询数据量较大时表现较好。IN用于判断某个字段值是否在一个集合或子查询的结果集中,适用于小规模数据的匹配,且需要子查询返回具体的列值。在选择使用EXISTS还是IN时,应该根据数据的大小、查询的目的和性能需求来决定。

weixin_42698221的博客 1107

EXISTS和IN的区别

条件

weixin_70280523的博客 8511

树莓派4B+DroneKit实战:手把手教你用Python控制无人机飞行(附避坑指南)

本文提供了一份详尽的树莓派4B与DroneKit配置实战指南,涵盖从硬件选型、软件环境搭建到Python编程控制无人机的完整流程。文章重点解决了ARM架构下的兼容性问题、MAVLink通信配置及端口管理等常见难题,并附带了实用的避坑指南和代码示例,帮助开发者构建稳定可靠的无人机控制系统。

weixin_29056781的博客 410

Sql语句中的in和exist

表展示     首先,查询中涉及到的两个表,一个user和一个order表,具体表的内容如下: user表 orer表 - in in在查询的时候,首先查询子查询的表,然后将内表和外表做一个[笛卡尔积](https://baike.baidu.com/item/%E7%AC%9B%E5%8D%A1%E5%B0%94%E4%B9%98%E7%A7%AF/6323173...

qq_33393542的博客 1000

智能座舱通信技术解析:从CAN总线到车载以太网与V2X

在汽车电子与智能网联快速融合的背景下,座舱智能化已不再是简单的屏幕堆砌,而是依赖底层通信技术构建的复杂系统。CAN总线因高可靠性与确定性传输,持续承担车身控制与安全信号的传递;车载以太网则凭借高带宽优势,成为多屏高清视频与OTA升级的核心通道;V2X车路协同技术进一步将座舱与外界的实时信息互联。理解这些技术的分工协作,是掌握智能座舱架构、开展座舱测试与故障排查的关键。本文从实际测试经验出发,梳理不同总线在座舱内部及外部的应用逻辑,结合低成本的实验台架搭建指南,展示从信号采集、网关转发到多媒体流传输的完整链路

weixin_29284657的博客 344

从翼型到湍流:用生活化案例图解空气动力学核心概念(中英双语版)

本文通过飞机机翼、F1赛车、高尔夫球等生活化案例,图解空气动力学核心概念。深入浅出地解释了攻角如何产生升力、边界层与流动分离如何影响阻力、马赫数如何划分速度世界,以及涡流与湍流的特性与应用。文章还介绍了计算流体动力学(CFD)这一现代数字风洞工具,帮助读者直观理解这些塑造现代交通与运动设计的无形之力。

metaverse5vr的博客 475

【mysql】in和exists的区别,not in、not exists、left join的相互转换

在oracle中,int中数据集的大小超过1000会报错;在mysql中,超过1000不会报错,但也是有数据量限制的,应该是4mb,但不建议数据集超过1000,因为in是可以走索引的,但in中数据量过大索引就会失效exist + not exists 是全量数据,这点与in不同。

weixin_44823875的博客 3318

Stable Diffusion跑图总爆显存?别急着换显卡,试试这个PYTORCH_CUDA_ALLOC_CONF参数调优

本文深入解析了Stable Diffusion运行中常见的显存不足问题,特别是由显存碎片化导致的假性OOM现象。通过详细讲解PYTORCH_CUDA_ALLOC_CONF参数中的max_split_size_mb设置技巧,提供了一套完整的显存优化方案,帮助用户在无需升级硬件的情况下显著提升AI绘画的稳定性与效率。

weixin_42524100的博客 347

SQL中NOT EXISTS 和NOT IN的区别

是 SQL 中用于的关键操作符,其核心意义是。NOT EXISTS对主表的每一行数据,检查子查询是否。如果子查询为空,则保留该行;否则过滤掉该行。

qq_45361075的博客 1673

微信小程序|基于小程序+云开发制作一个租房小程序

经济发展的同时伴随着大批人群的流动,租房需求一直是持久不衰的话题,如何租好房,好租房,跟随此文一起制作一个租房小程序,让租房不再困难。

商务合作 / 项目定制 / 学习交流。个人vx:lovely_wml 4929

ppt保存时嵌入字体,但找不到字体使用的位置的解决办法

摘要 当PPT提示无法保存嵌入字体时,可通过VBA代码快速定位使用该字体的文本。具体步骤如下: 按ALT+F11打开VBA编辑器,新建模块并粘贴提供的代码; 运行代码后输入目标字体名称(如“方正兰亭黑简体”); 程序将列出所有使用该字体的幻灯片编号及对应文本内容; 修改这些文本的字体即可解决保存问题。该方法高效精准,适用于排查PPT字体嵌入失败的情况。(150字)

智慧空间实验室 1400

Exists、 In 、Not Exists、Not In 区别和效率

Exists、 In 、Not Exists、Not In 区别和效率 ​ Exists和in的基本工作原理就不说了可以看这篇博文:https://blog.youkuaiyun.com/qq_38238296/article/details/86601765 ​关于exists和in的效率问题 ​ 很多博客上说in适用于外表大内表小的情况,exists适用于外表小内表大的情况 如果查询的两个表大小相当,那么用in和exists差别不大。 如果两个表中一个较小,一个是大表,则子查询表大的用exists,子查询

eagle89的专栏 902

Unity之OpenXR+XR Interaction Toolkit实现 Gaze眼部追踪

在虚拟现实(VR)和增强现实(AR)应用中,眼动追踪是一项强大而受欢迎的技术。它可以让开发者更好地理解用户的注意力和行为,并创造出更加沉浸和智能的体验。在本文中,我们将探讨如何使用 Unity OpenXR 实现Gaze眼部追踪功能。

TxNet 1751

Exists、 In 、Not Exists、Not In 四种的执行机制区别

Exists、 In 、Not Exists、Not In 区别和效率 ​ Exists和in的基本工作原理就不说了可以看这篇博文:https://blog.youkuaiyun.com/qq_38238296/article/details/86601765 ​关于exists和in的效率问题 ​ 很多博客上说in适用于外表大内表小的情况,exists适用于外表小内表大的情况 如果查询的两个表大小相当,那么...

qq_38238296的博客 1689

【项目实战】自动化测试软件VectorCAST介绍

VectorCAST是一款先进的自动化测试软件。VectorCAST是一款功能强大、易于使用的自动化测试软件。VectorCAST适用于各种嵌入式系统的测试。VectorCAST为嵌入式系统的测试提供了一种高效、可靠的解决方案。VectorCAST提供了一整套完整的测试工具,包括测试管理、代码覆盖、缺陷定位、报告生成等,以帮助开发人员提高测试效率,确保软件质量。VectorCAST支持。

奶爸的编程之路,也就一周冷个三天 2011

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

except、not exists和not in的区别和效率对比

NOT IN:如果子查询结果包含NULL,整个查询结果会返回空集。NULL的比较在 中是“未知”(Unknown),NOT IN无法判断NULL是否属于集合。-- table2 包含 NULL,导致结果为空NOT EXISTSNULL:关联子查询中,NULL不会影响逻辑判断。-- 即使 table2 包含 NULL,仍能正确返回 table1 中无匹配的行EXCEPTNULL:将NULL视为相等(两个NULL被视为同一值)。-- 即使包含 NULL,仍能正确返回差集EXCEPTNOT IN。

Alfie的博客 1042

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

exists 和not exists 用法简介及与IN和not In的区别

使用 EXISTS 和 NOT EXISTS 引入的子查询可用于两种集合原理的操作:交集与差集。两个集合的交集包含同时属于两个原集合的所有元素。差集包含只属于两个集合中的第一个集合的元素。EXISTS:指定一个子查询,检测行的存在。NOT EXISTS:指定一个子查询,检查行的不存在exists (sql 返回结果集为真) not exists (sql 不返回结果集为真=no r

zhoubo200的专栏 3794

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Oracle的exists与not exists的区别,以及in,not in的区别

exists (sql 返回结果集为真) not exists (sql 不返回结果集为真) 如下: 表A ID NAME 1    A1 2    A2 3  A3 表B ID AID NAME 1    1 B1 2    2 B2 3    2 B3 表A和表B是1对多的关系 A.ID =&gt; B.AID SELECT ID,NAME FROM A WHERE EXIST (SELECT...

qq_39736103的博客 402

not in和not exists区别

"Not in"和"Not exists"主要的区别在于它们所检查的内容不同:"Not in"是在一个已知的列表中检查某个值;而"Not exists"则是在某个表(子查询)中是否存在相关的值。总之,"Not in"用于过滤行,而"Not exists"用于验证子查询中是否存在满足条件的行。"Not in"是一种用于查询的运算符,用于在某个列中查找不包含指定值或列表的行。"Not exists"是一个用于子查询的运算符,用于检查是否存在满足条件的行。这将返回table_name1中不存在满足给定条件的行。

遇上的博客 3801

EXISTS、IN、NOT EXISTS、NOT IN的区别

EXISTS、IN、NOT EXISTS、NOT IN的区别:in适合内外表都很大的情况,exists适合外表结果集很小的情况。exists 和 in 使用一例 =========================================================== 如下sql:update p_container_decl cdset cd.ANNUL_FLAG=0001,

数据库技术成长之路...... 1152

exists和in的效率区别_not in与not exists的区别

出处: https://blog.youkuaiyun.com/baidu_37107022/article/details/77278381in和existsin是把外表和内表作hash连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询,一直以来认为exists比in效率高的说法是不准确的。如果查询的两个表大小相当,那么用in和exists差别不大;如果两个表中一个较小一...

weixin_39591720的博客 250

not in 与not exists区别

1、对于not exists查询,内表存在空值对查询结果没有影响;对于not in查询,内表存在空值将导致最终的查询结果为空。 2、对于not exists查询,外表存在空值,存在空值的那条记录最终会输出;对于not in查询,外表存在空值,存在空值的那条记录最终将被过滤,其他数据不受影响。 eg: select * FROM customer a where not ex...

zhuzi51的专栏 3830

SQL中的in与not in、exists与not exists的区别以及性能分析

1、in和exists in是把外表和内表作hash连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询,一直以来认为exists比in效率高的说法是不准确的。 如果查询的两个表大小相当,那么用in和exists差别不大;如果两个表中一个较小一个较大,则子查询表大的用exists,子查询表小的用in; 例如:表A(小表),表B(大表) select*fromAwhereccin(selectccfromB)-->效率低,用到了A表上cc列...

CXY_QIQI的博客 4441

oracle-not in 和not exists的区别

oracle-not in 和not exists的区别 1.not in 和not exists效率上的区别 在查询语句中使用not in的时候会对内表进行全表扫描,没有用到索引。而not exists的子查询仍然会用到表上的索引。所以无论的大表还是小表,使用not exists都会比使用not in 要快。当然这的前提是表中有索引。 2.not in 和not exists结果上的区别

GreenAppple的专栏 2303

数据库——SQL中in,not in,exists, not exists的区别

1.exist,not exist一般都是与子查询一起使用;In可以与子查询一起使 用,也可以直接in (a,b…..)2.exist会针对子查询的表使用索引. not exist会对主子查询都会使用索引. in与子查询一起使用的时候,只能针对主查询使用索引. not in则不会使用任何索引. 注意,一直以来认为exists比in效率高的说法是不准确的。3.exists的原理: exists做为w

sinat_35705122的博客 1425

浅析sql中的in与exists,not in与not exists的区别

在我们平时开发中书写SQL语句时,in、not in、exists、not exists都是可能会用到的,那么它们之间有什么区别呢,有没有什么可能潜在的坑呢? 创建测试数据库: CREATE TABLE `testa` ( `id` int(11) NULL DEFAULT NULL ); INSERT INTO `testa` VALUES (1); INSERT INTO `testa` VALUES (2); INSERT INTO `testa` VALUES (NULL); INSERT

Coder-文小白的博客 627
上一篇: HIVE备份--批量导出HIVE建表语句
下一篇: HIVE分区表新增字段后新增字段值为空,需要带分区加字段
T___Z
博客等级 码龄14年 0粉丝 1原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值