Gol*_*old 13 sql database oracle
Oracle查询之间not in和之间的区别是什么not exists?
我not in什么时候使用?而且not exist?
Nic*_*int 24
如果结果中包含值,则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);
Run Code Online (Sandbox Code Playgroud)
注意:它们的关键区别在于test_b包含一个null值.
select * from test_a where col1 not in (select col1 from test_b);
Run Code Online (Sandbox Code Playgroud)
没有返回任何行
select * from test_a where
not exists
(select 1 from test_b where test_b.col1 = test_a.col1);
Run Code Online (Sandbox Code Playgroud)
返回
col1
====
d
e
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42075 次 |
| 最近记录: |