我需要选择7A班学生的考试成绩,但需要查看另一张表(student_profile)来识别7A中的学生(由student_id标识)。 我不知道哪下面的方法会更快,假定索引为student_id数据在两个表中创建:关于SQL查询的问题
方法1:
select * from exam_results r
where exists
(select 1
from student_profile p
where p.student_id = r.student_id
and p.class = '7A')
方法2:在提前
select * from exam_results
where student_id in
(select student_id
from student_profile
where class = '7A')
谢谢,
乔纳森
去'EXISTS'。 –
在任何现代的sql引擎上,查询执行计划都是一样的。 – Jodrell
JW的+1。 ** [请参考链接进一步澄清你的疑惑](http://stackoverflow.com/questions/5018284/mysql-in-queries-terribly-slow-with-subquery-but-fast-with-explicit-values) ** – Luv