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

1 Answer 1

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

FROM Paziente AS Paz
LEFT JOIN Visita AS Vis  ON Vis.Paziente=Paz.CF
WHERE  (SELECT MAX(Parcella) FROM Visita)=Vis.Parcella;
Thank you, is perfect! I can't vote because my reputation is inferior of 15 – Fab95s 55 mins ago
Thanks @Fab95s happy to have helped! Can still select this as the correct answer? – WJS 52 mins ago
I just found out how to put the right answer, done! – Fab95s 48 mins ago
Thank you @Fab95s :) – WJS 11 mins ago