8
A
回答
5
0
可能存在性能差异,存在速度更快。
最重要的区别是处理空值。您的查询看起来可能与in和exists一样,但是当您的子查询返回null时,您可能会感到震惊。
您可能会发现存在空值导致存在失败。
请参阅Joe Celko的'用于聪明人的SQL'以更好地解释何时使用每一个。
0
不在为一组元素中的元素进行测试,因此它更简单。
不存在可以处理更复杂的查询,包括分组(例如具有sum(x)= z或具有count(*)> 3),具有多个条件(例如,匹配多个元素)的结果,并且可以利用索引。
在某些情况下不容易做比不存在。我通常会发现这是我测试值集合中关键字段值的位置。
作为一个大拇指的规则,我宁愿不存在,因为它涵盖了更多的情况而不是不存在。不存在可以用于每个不用于的情况,但不是相反。
13
NOT IN之间的差异和NOT EXISTS那里有包括在结果NULL
值变得清晰。
例如:
create table test_a (col1 varchar2(30 char));
create table test_b (col1 varchar2(30 char));
insert into test_a (col1) values ('a');
insert into test_a (col1) values ('b');
insert into test_a (col1) values ('c');
insert into test_a (col1) values ('d');
insert into test_a (col1) values ('e');
insert into test_b (col1) values ('a');
insert into test_b (col1) values ('b');
insert into test_b (col1) values ('c');
insert into test_b (col1) values (null);
注意:它们主要的区别在于test_b
包含null
值。
select * from test_a where col1 not in (select col1 from test_b);
没有行返回
select * from test_a where
not exists
(select 1 from test_b where test_b.col1 = test_a.col1);
返回
col1
====
d
e
+0
@金:我认为你应该接受这个答案,将有助于未来的游客直接得到公牛的眼睛。 – hagrawal 2017-11-19 18:10:59
相关问题
- 1. 保存在proto和这个之间有什么区别?
- 2. dpm()和dsm()之间有什么区别?
- 3. @dynamic和@synthesize之间有什么区别?
- 4. vbNullString和“”之间有什么区别吗?
- 5. * zoom和zoom之间有什么区别?
- 6. String.Concat,string.format和+之间有什么区别?
- 7. StaticLayout和DynamicLayout之间有什么区别
- 8. WebServiceBinding.EmitConformanceClaims和WebServiceBinding.ConformanceClaims之间有什么区别?
- 9. :: after和after之间有什么区别?
- 10. %.02f和%.2f之间有什么区别?
- 11. {$ var}和$ var之间有什么区别?
- 12. ReleaseFloatArrayElements和DeleteLocalRef之间有什么区别
- 13. {0}和“”之间有什么区别?
- 14. getA()和this.getA()之间有什么区别?
- 15. @observable和@published之间有什么区别
- 16. $ {}和#{}之间有什么区别?
- 17. url.getFile()和getpath()之间有什么区别?
- 18. KVC和Properties之间有什么区别?
- 19. Lazy.Force()和Lazy.Value之间有什么区别
- 20. “层”和“层”之间有什么区别?
- 21. 1.1em和1.05em之间有什么区别?
- 22. proc和lambda之间有什么区别?
- 23. ViewFlipper和ViewSwitcher之间有什么区别
- 24. typedef和宏之间有什么区别?
- 25. “$^N”和“$ +”之间有什么区别?
- 26. NSInvocation和block之间有什么区别?
- 27. -existingObjectWithID:error:和-objectWithID之间有什么区别?
- 28. {0}和+之间有什么区别?
- 29. Locationmanager.locationListener和com.google.android.gms.location.LocationListener之间有什么区别?
- 30. $ .cache和$ .data之间有什么区别?
不要忘了处理空值:http://stackoverflow.com/questions/1699424/what-the-difference -oracle-in-and-not-exist-in-oracle-query/1703712#1703712 – 2009-11-09 20:52:04
汤姆凯特链接肯定得到了问题的根源。 – 2009-11-09 20:53:41