MySql Error #1111 - Invalid use of group function
If you try to use an aggregated function in a context where a non-aggregated function is expected, you'll get this error:
MySql Error #1111 - Invalid use of group function
As an example, this query will raise error 1111:
SELECT id, COUNT(*)
FROM yourtable
WHERE COUNT(*) > 1
GROUP BY id
since the WHERE
clause is evaluated before the GROUP BY
, the COUNT(*)
is not known in this context. In this example you have to use HAVING
clause instead:
SELECT id, COUNT(*)
FROM yourtable
GROUP BY id
HAVING COUNT(*) > 1