题解 | 使用含有关键字exists查找未分配具体部门的员工的所有信息。
使用含有关键字exists查找未分配具体部门的员工的所有信息。
https://www.nowcoder.com/practice/c39cbfbd111a4d92b221acec1c7c1484
SELECT e.*
from employees as e
where not exists(
select 1
from dept_emp de
where de.emp_no=e.emp_no
);
select 1
from dept_emp de
where de.emp_no=e.emp_no不返回具体列,而是如果de.emp_no=e.emp_no,则返回1,否则返回NULL,用来判定某行是否存在,用1的话不用占据太多空间,性能更快。not exists可以把不存在的找出来