exist用法

exists表示()内子查询语句返回结果不为空说明where条件成立就会执行主sql语句,如果为空就表示where条件不成立,sql语句就不会执行。not exists和exists相反,子查询语句结果为空,则表示where条件成立,执行sql语句。负责不执行。

之前在学Oracle数据库的时候,接触过exists,做过几个简单的例子,,如

1.如果部门名称中含有字母A,则查询所有员工信息(使用exists)
select * from emp where exists (select * from dept where dname like ‘%A%’ and deptno = emp.deptno) temp and deptno=temp.deptno;

猜你喜欢

转载自blog.csdn.net/jtpython666/article/details/119925289