您的位置:首页 > 数据库 > Oracle

oracle 中 in 和exists用法区别

2015-12-04 14:53 441 查看
select * from sc where cno='c001' and sno in(select sno from sc where cno='c002');
select * from sc where cno='c001' and exists(select sno from sc where cno='c002');
请问这两句运行结果为什么不一样?

2013-09-11 20:41提问者采纳

是这样的
in 是返回的结果集

比如你只运行这一句
select sno from sc where cno='c002'
返回的是一列sno

但是exists则不同,返回的是布尔值

虽然里边那个没法单独运行
select * from sc a where cno='c001' and exists(select sno from sc b where cno='c002' and a.sno=b.sno) ;
后边必须要写上两者的关联
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: