exists和not exists的应用


1.exists和not exists的本质是判断存在或不存在一个元组,所以判断是否存在的值都是 select * 

1 where not exists(
2                 select * #一定是用该方法来写
3                 from employees e2 
4                 where e2.department_id = d.department_id  and job_id = "ST_CLERK"
5                 );

2.用到exists或是not exists都用到了跨表查询,所以一定要附上连接条件

where not exists(
                select *
                from employees e2 
                where e2.department_id = d.department_id  and job_id = "ST_CLERK" #加上表的连接条件
                );