Search code examples
mysqlsqlmysql-error-1111

Error Code: 1111. Invalid use of group function (SQL)


I created this query in MySQL for a dental practice

SELECT Paz.Nome, Paz.Cognome FROM Paziente AS Paz, Visita AS Vis WHERE Vis.Paziente=Paz.CF AND MAX(Vis.Parcella)=Vis.Parcella

But not work for the error 1111. Help me please


Solution

  • Try this, I've specified the second table in a join, the max statement needs to be in the form of a subquery:

    SELECT 
    Paz.Nome, 
    Paz.Cognome 
    FROM Paziente AS Paz
    LEFT JOIN Visita AS Vis  ON Vis.Paziente=Paz.CF
    WHERE  (SELECT MAX(Parcella) FROM Visita)=Vis.Parcella;