通过exists判断数据,并查找存在的数据

----通过exists判断数据,并查找存在的数据
---以scott用户的emp 及dept表为例

select * from emp;
select * from dept;

 

---查找emp表中的数据,且员工部门在dept表中能找到
select * from emp g
where 1=1 ---1=1可以不用,此用法方便再后边实现and条件的注释
and exists (select 1 from dept t where t.deptno = g.deptno);
----查找dept表中的数据,且员工部门在emp表中能找到
select * from dept t
where 1=1 
and exists (select 1 from emp e where t.deptno = e.deptno)

 

posted @ 2017-05-18 09:22  黄景新  阅读(651)  评论(0编辑  收藏  举报