首页 > 技术文章 > <正则吃饺子> :关于oracle 中 exists 、not exists 的简单使用

zhengzeze 2017-08-14 11:33 原文

话不多说,简单的总结而已。网络上很多很详细介绍。

例如,博文http://blog.csdn.net/zhiweianran/article/details/7868894  当然这篇也是转载的,原创地址就不深究了。学习就好。

具体的可以参照这个博文地址,介绍的还是比较详细的。

 

---我的简单记录,如下:


select * from a ;

insert into a(id,name) values(1,'name1');
insert into a(id,name) values(2,'name2');
insert into a(id,name) values(3,'name3');


select * from b ;

insert into b(id,aid,bname) values(1,1,'bname1');
insert into b(id,aid,bname) values(2,2,'bname2');
insert into b(id,aid,bname) values(3,2,'bname3');

exists (sql 返回结果集为真)
not exists (sql 不返回结果集为真)

--exists
select * from a where exists (select  * from b where b.aid = a.id) ;
--in
select * from a where a.id in (select b.aid  from b where b.aid = a.id) ;


-- not exists
select * from a where not exists (select  * from b where b.aid = a.id) ;

--not in
select * from a where a.id not in (select b.aid  from b where b.aid = a.id) ;

推荐阅读