0
Hello friends I’m having a hard time finding what is wrong in my selection code (SELECT) in mysql, this taking more than 70sec do not know why. Someone there to help me please?
Code:
SELECT id_aluno, nome_aluno, ano_lectivo, data data_pagamento_m, nome_classe, codigo_classe, nome_curso, valor_curso1, multa
FROM tb_matriculas
LEFT JOIN tb_classe ON tb_matriculas.classe = tb_classe.id_classe
LEFT JOIN tb_curso ON tb_curso.codigo_curso = tb_matriculas.curso
WHERE data_pagamento_m < '$data_nova '
AND data_pagamento_m <> '2017-01-01'
AND YEAR(data_pagamento_m) = '$ano_select'
AND classe BETWEEN '$classe1'
AND '$classe2'
AND classe <> '10'
AND curso BETWEEN '$curso1' AND '$curso2'
AND turma BETWEEN $turma1 AND $turma2
AND periodo BETWEEN '$periodo1' AND '$periodo2'
GROUP BY id_aluno
create indexes for your table, which will result in more speed in your search
– Victor
Why
GROUP BY id_aluno
?– Marconi
Another question, are you sure it is
LEFT JOIN
, recommend reading: What is the difference between INNER JOIN and OUTER JOIN?– Marconi
Hello thanks, I have created a indece in the table tb_matriculas, the GROUP BY id_student to group per student
– José Manuel Barros
Run a EXPLAIN of your query and analyze the result.
– anonimo
Function YEAR breaks an index if there is one in the data_payment_m column , and seems to have a model problem because payment is an attribute of which table ? There is only one payment ?
– Motta
You use the GROUP BY clause but do not use any aggregation function in your selection list. What you want to group?
– anonimo