第38章 子查询优化——子查询转换为连接 - xiaoboluo768/qianjinliangfang GitHub Wiki

38.2 优化方案

select count(*) from employees as a,(select distinct emp_no from dept_emp where dept_no = 'd007')b where a.emp_no = b.emp_no;

mysql> select count(*) from employees as a where exists (select emp_no from dept_emp b where a.emp_no = b.emp_no and b.dept_no = 'd007');
......
1 row in set (0.44 sec)

mysql> select count(*) from employees as a,(select distinct emp_no from dept_emp where dept_no = 'd007')b where a.emp_no = b.emp_no;
......
1 row in set (0.07 sec)

上一篇:第37章 分页查询优化 | 下一篇:第39章 子查询优化——使用delete删除数据