sql刷题day4

1 使用含有关键字exists查找未分配具体部门的员工的所有信息。

思路一

对于每一个员工,查询他的id是否存在于dept_emp

select *
from employees
where NOT EXISTS(
    select *
    from dept_emp
    where
    employees.emp_no=emp_no
)

思路二

使用 not in

SELECT *
FROM employees
WHERE emp_no NOT IN (SELECT emp_no
                    FROM dept_emp);

对比使用可以更好理解exist语句

原文地址:https://www.cnblogs.com/wjune-0405/p/14115053.html