exists后面跟一个布尔值
SELECT * FROM EMP WHERE EXISTS (SELECT * FROM DEPT WHERE DEPTNO = 10); SELECT * FROM EMP WHERE EXISTS (SELECT * FROM DEPT WHERE DEPTNO = 50);
查询子查询中外键有记录的数据
a.查询出DEPT表中有人的部门 SELECT * FROM DEPT D WHERE EXISTS (SELECT * FROM EMP E WHERE E.DEPTNO = D.DEPTNO); 或 SELECT * FROM DEPT WHERE DEPTNO IN (SELECT DEPTNO FROM EMP); b.把EMP表中最低工资的人去掉 SELECT * FROM EMP E1 WHERE EXISTS (SELECT * FROM EMP E2 WHERE E1.SAL>E2.SAL);
关键字--exists用法
最新推荐文章于 2024-08-13 15:52:42 发布