我有两个表,例如Employee
和Project
表:
Employee (id, dept, joining_date)
Project (emp_id, project)
从表Project
中获得外键。Employee
我必须查询project
并按他们的顺序dept
返回。哪个查询将在以下查询的大数据集上运行得更快?Employee
joining_date
select * from Employee where id in (select p.emp_id from Project p join Employee e on p.emp_id = e.id where p.project = 'project1' and e.dept = 'dept1') order by joining_date
select * from Employee where id in (select p.emp_id from Project p join Employee e on p.emp_id = e.id where p.project = 'project1' and e.dept = 'dept1') and dept = 'dept1' order by joining_date
或者有没有更好更简单的方法来做到这一点?