mysql description

Asked

Viewed 53 times

-4

look at my code

select count(alunocursos.codAluno), alunocursos.codCurso from
alunocursos join aluno on (aluno.id = alunocursos.codAluno) group by
alunocursos.codCurso

this will make me return the amount of students who held each course i also have the courses table (id, description)

how do i make in the above query return me, instead of course id, the course description?

  • Put the MER, if possible, is easier to help.

  • Look what you’ve programmed here: GROUP BY alunocurso.codCurso ... should ask to group by DESCRIPTION course. You have tried?

1 answer

0


Assuming that the table alunocursos has a link with the table cursos you could do it using two INNER JOINS:

SELECT COUNT(alunocursos.codAluno), alunocursos.codCurso, cursos.descricao FROM
alunocursos 
INNER JOIN aluno ON (aluno.id = alunocursos.codAluno),
INNER JOIN cursos ON (cursos.id = alunocursos.codCurso)    
GROUP BY alunocursos.codCurso;

Thus returns both the codCurso as the description of it, if you want to return only the description just remove the alunocursos.codCurso of SELECT.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.