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

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

http://www.nowcoder.com/practice/c39cbfbd111a4d92b221acec1c7c1484

exists详细解释
exists语法:exists(完整的查询语句),结果返回true或false
若返回true,则将外层查询表的记录保存,若为false,则删除记录。

from employees e
where not exists
(select emp_no
from dept_emp d
 where d.emp_no=e.emp_no);```
本题先执行外层,遍历employees表,然后根据exists后面的结果进行筛选,最后符合的结果输出。
exists与exist相反。

与in的区别
in判断则是先查内部不子查询结果,然后与外表进行内连接。(带条件的笛卡儿积)。输出结果。
如果是 not in 和 not exists
not in需要进行外表全表扫描,无法使用索引。而此时not exists更快。

全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务