Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the maximum count using mysql?

Tags:

mysql

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
like image 799
user2225190 Avatar asked May 08 '13 12:05

user2225190


People also ask

Can I do a max count * in MySQL?

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.

How do you find Max count in SQL?

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.

How do I find the highest number in MySQL?

You can use ORDER BY clause or aggregate function MAX() to select the maximum value.

Can you do a max count in SQL?

And the short answer to the above question is, no. You can't. It is not possible to nest aggregate functions.


1 Answers

Try:

SELECT NAME, COUNT(*) as c FROM table GROUP BY name ORDER BY c DESC LIMIT 1

like image 171
matsko Avatar answered Sep 28 '22 20:09

matsko