如何使用内部联接使选择查询更高效

时间:2019-04-05 17:12:13

标签: mysql sql join inner-join

我想从多个表中选择数据,但是随着数据变大,从MySQL数据库获取数据时,我的系统变慢。

如何使该查询更有效。

SELECT s.id,s.regiNo, 
       s.firstName as fname, 
       s.middleName as mname, 
       s.lastName as lname, 
       s.gender, s.class_group, c.subjects,
       e.mid_term, e.count_assessment, e.examid, 
       e.scored, e.internaltype, e.Class, 
       e.Year,e.total_score,e.sub_highest,e.sub_lowest,
       e.first_term,e.second_term,e.third_term,e.avg_score 
FROM student s 
inner join exam e on s.regiNo = e.Roll_Number 
inner join subjects c on e.sub_id = c.subect_code  
group by s.regiNo, s.firstName, s.middleName, s.lastName, 
         s.gender, s.class_group, c.subjects,
         e.mid_term, e.count_assessment, e.examid, e.scored, e.internaltype, 
         e.Class, e.Year,e.total_score,e.sub_highest,e.sub_lowest,
         e.first_term,e.second_term,e.third_term,e.avg_score,s.id

1 个答案:

答案 0 :(得分:1)

我看到您有ID列,如果这是您的PK,那么您可能需要一些索引。

尝试在JOINING列上创建索引。例如

上的regiNo,Roll_Number