user3070123 user3070123 - 7 months ago 22
PHP Question

#1111 - Invalid use of group function: MAX COUNT doesn't work with MYSQL5.5

IN MY DB , I have a table userInteret , i wanna to select the max on commun interet between user
I tried this requete :

SELECT nomInteretUser,idUser,COUNT(nomInteretUser) FROM `userInteret`
WHERE nomInteretUser IN('piano','flute','chien') GROUP BY idUser


BUt I want the MAX of this COUNT , when I tried this :

SELECT MAX(COUNT(nomInteretUser))FROM userInteret
WHERE nomInteretUser IN('piano','flute','chien') GROUP BY idUser;


ᐧ It always make error :
Erreur
Requête SQL : Documentation

SELECT MAX(COUNT(nomInteretUser))FROM userInteret
WHERE nomInteretUser IN('piano','flute','chien') GROUP BY idUser;


MySQL a répondu: Documentation

1111 - Invalid use of group function



ANY Help

Answer
SELECT idUser,COUNT(nomInteretUser) counts 
FROM userInteret
WHERE nomInteretUser IN('piano','flute','chien') 
GROUP BY idUser
ORDER BY counts DESC LIMIT 1