MySQL: Invalid use of group function

You need to use HAVING, not WHERE. The difference is: the WHERE clause filters which rows MySQL selects. Then MySQL groups the rows together and aggregates the numbers for your COUNT function. HAVING is like WHERE, only it happens after the COUNT value has been computed, so it’ll work as you expect. Rewrite your subquery as:

MySQL: Invalid use of group function

You need to use HAVING, not WHERE. The difference is: the WHERE clause filters which rows MySQL selects. Then MySQL groups the rows together and aggregates the numbers for your COUNT function. HAVING is like WHERE, only it happens after the COUNT value has been computed, so it’ll work as you expect. Rewrite your subquery as: