exists后面(相关子查询)
- 语法:
exists (完整的查询语句)
- 结果:
1或0
SELECT EXISTS(SELECT employee_id FROM employees WHERE salary=300000) ;
#案例:查询有员工的部门名
#EXISTS
SELECT department_name
FROM departments d
WHERE EXISTS (
SELECT *
FROM employees e
WHERE d.department_id=e.department_id
);
#IN
SELECT department_name
FROM departments d
WHERE d.department_id IN(
SELECT department_id
FROM employees
);