查询优化
查找最晚入职员工的所有信息
http://www.nowcoder.com/questionTerminal/218ae58dfdcd4af195fff264e062138f
逐步优化
- 相关子查询 20ms
select * from employees where hire_date = (select max(hire_date) from employees);
- 不相关子查询 15ms
select e1.* from employees e1 join (select hire_date from employees order by hire_date desc limit 1) e2 on e1.hire_date = e2.hire_date;
- 左连接 19ms
select e1.* from employees e1 left join employees e2 on e1.hire_date < e2.hire_date where e2.emp_no is null;
结果表明:以上三种方法中,不相关子查询最快