exits函数

来源:互联网 发布:26周四维彩超标准数据 编辑:程序博客网 时间:2024/06/03 20:33

把部门位置位于达拉斯的所有员工工资涨到1.2

update emp set sal=sal*1.2 where exists (select 1 from dept where deptno=emp.deptno and loc='DALLAS');  

等同于
update emp a set sal=sal*1.2 where exists (select 1 from dept b where b.deptno=a.deptno and loc='DALLAS');




update emp set sal=sal*1.2 where exists (select avg(sal) from dept ); ---更新了14行,因为emp和dept做了一个半连接


------------------ exists半连接----------------------------
查询部门在纽约的雇员信息
select * from emp a where exists (select 1 from dept b where a.deptno=b.deptno and loc='NEW YORK');        ----exists子句返回一个true,前面的主句就会返回信息
结果等同于
select a.* from emp a,dept b where a.deptno=b.deptno and loc='NEW YORK';
但是前者效率高
0 0
原创粉丝点击