Please let me know what is wrong with the below command
mysql> select max(count(*)) from emp1 group by name;
ERROR 1111 (HY000): Invalid use of group function
No, we can't use a MAX(COUNT(*) and we can not layer aggregate functions on top of one another in the same SELECT clause. In a subquery, the inner aggregate would have to be performed.
To find the max value of a column, use the MAX() aggregate function; it takes as its argument the name of the column for which you want to find the maximum value. If you have not specified any other columns in the SELECT clause, the maximum will be calculated for all records in the table.
You can use ORDER BY clause or aggregate function MAX() to select the maximum value.
And the short answer to the above question is, no. You can't. It is not possible to nest aggregate functions.
Try:
SELECT NAME, COUNT(*) as c FROM table GROUP BY name ORDER BY c DESC LIMIT 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With