why my query take about 2 minutes to process?
i need to take attribute from 8 table.
how can i join those table and make it a fast query?
the reason why i want to join those table is bacause i want to fetchAll(PDO::FETCH_ASSOC) from user input progCode
this is my query :
"SELECT DISTINCT a.`ProgCode`, a.`Program`
FROM (select `i`.`name` AS `LC`,`f`.`name` AS `Intake`,`a`.`student_id`
AS `student_id`,`b`.`matricNo`
AS `matricNo`,`b`.`name`
AS `Nama`,`a`.`sem_id`
AS `sem_id`,`c`.`name`
AS `Sessi`,`e`.`code`
AS `ProgCode`,`e`.`name`
AS `Program`,`a`.`sub_id`
AS `sub_id`,`d`.`code`
AS `SubCode`,`d`.`name`
AS `Subject`,`a`.`grade`
AS `grade`,`h`.`credit`
AS `CurrentCreditHour`,`g`.`totalcredit`
AS `TotalCreditHour`,`g`.`gpa`
AS `GPA`,`g`.`cgpa`
AS `CGPA` from ((((((((`admin_sub_mark` `a` join `enrl_student` `b`)
join `struc_session` `c`)
join `struc_session` `f`)
join `struc_subject` `d`)
join `struc_program` `e`)
join `admin_sem_wise_cgpa` `g`)
join `admin_sem_wise_gpa` `h`)
join `struc_learningcentre` `i`)
where ((`b`.`id` = `a`.`student_id`)
and (`d`.`id` = `a`.`sub_id`)
and (`c`.`id` = `a`.`sem_id`)
and (`e`.`id` = `b`.`program_id`)
and (`f`.`id` = `b`.`intake_id`)
and (`i`.`id` = `b`.`learningCenter_id`)
and (`a`.`student_id` = `g`.`student_id`)
and (`a`.`sem_id` = `g`.`sem_id`)
and (`h`.`student_id` = `g`.`student_id`)
and (`h`.`sem_id` = `g`.`sem_id`)) order by `b`.`name`) a
ORDER BY `Program` ASC"
this is my explain query:
id| select_type | table | type | possible_keys | key | key_len | ref | rows | Extra
1 | SIMPLE | g | ALL | NULL |NULL | NULL | NULL| 6049 | Using temporary; Using filesort
1 | SIMPLE | h | ALL | NULL | NULL | NULL | NULL | 6055 | Using where |
1 | SIMPLE | c | eq_ref | PRIMARY | PRIMARY | 257 | educate_aeu2.g.sem_id 1
1 | SIMPLE | b | eq_ref | PRIMARY | PRIMARY | 257 | educate_aeu2.h.student_id 1 Using where
1 | SIMPLE | f | eq_ref |PRIMARY | PRIMARY | 257 | educate_aeu2.b.intake_id 1
1 | SIMPLE | e | eq_ref | PRIMARY | PRIMARY | 257 | educate_aeu2.b.program_id 1
1 | SIMPLE | i | eq_ref | PRIMARY | PRIMARY | 257 | educate_aeu2.b.learningCenter_id 1
1 | SIMPLE | a |ALL | NULL | NULL | NULL | NULL | 17077 | Using where
1 | SIMPLE | d | eq_ref | PRIMARY | PRIMARY | 257 | educate_aeu2.a.sub_id 1
EXPLAIN
andEXPLAIN EXTENDED
your query better than we can, because MySQL already knows what the schema's look like – Elias Van Ootegem