3
I have a table in SQL Server and I’m having trouble making a query.
I have a table like this:
alunos
ra nome serie cod_curso
23 joão 1 EI
23 joão 2 EI
23 joão 3 EI
44 maria 5 EF
44 maria 6 EF
61 jose 10 CCO
32 ana 7 PED
78 ana 8 PED
I need to select the highest value of serie
for each ra
. The result of the consultation should look like this:
alunos
ra nome serie cod_curso
23 joão 3 EI
44 maria 6 EF
61 jose 10 CCO
78 ana 8 PED
If I select MAX(serie)
but it won’t work. I need to select MAX(serie)
according to each ra
, but I don’t know how to do it.
When I use this query, it returns this error:
Column 'alunos.nome' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
– Amanda Lima
Adds group by ra, name, cod_course at the end of the query.
– Yure Pereira
But if my table has 30 columns I will have to put the 30 in group by?
– Amanda Lima
Yes, I would need to, but see the other way I put it with Inner Join.
– Yure Pereira