Problem with SQL statement when wanting to group (Group By)

1

The problem lies in the moment in which I want to execute the following sentence:

SELECT Id_Temporada, IdSerie, NombreTemporada, NumeroTemporada,
       Id_TemporadaC, Id_CapituloT, NombreCapitulo, NumeroCapitulo,
       DescripcionCapitulo 
  FROM Temporadas_Serie 
       INNER JOIN Capitulos_TemporadaS ON Temporadas_Serie.Id_Temporada =Capitulos_TemporadaS.Id_TemporadaC 
 WHERE Temporadas_Serie.IdSerie='XX'  
 GROUP BY NumeroTemporada, NombreCapitulo

as you can see by doing an INNER JOIN which is perfect, but when you place the GROUP BY, the following error automatically appears:

Column 'Temporadas_Serie.Id_Temporada' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

What can I do?

    
asked by Atejada 21.06.2018 в 20:49
source

1 answer

1

Indeed, what Patricio and German mention is correct:

  • All the fields that you include in a SELECT clause must be in the same way in the GROUP BY clause, unless you use an aggregate function in SELECT for those fields that you do not want to group.

    Some aggregate functions are:

    SUM, MIN, MAX, AVG... etc.
    
  • The type of JOIN you are using is not valid, the OUTER you can use it in

    LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN
    
  • answered by 23.06.2018 / 07:08
    source