Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get max repeated count with sql

Tags:

mysql

count

Hi have a table name is cou

name      type

kasu      1
kasu      4
kasu      3
nimal     1
nimal     2

I need this answer as

name  cnt

kasu  3
like image 870
Kasun Shamentha Avatar asked Jun 09 '12 15:06

Kasun Shamentha


1 Answers

SELECT name, COUNT(name) AS `cnt`
FROM cou 
GROUP BY name
ORDER BY `cnt` DESC
LIMIT 1

ok so, sorry, i didn't find something more elegant, so I did it the stupid way. There is definetly another way of doing it though...

Demo with your example

Another Example after adding inputs

like image 60
Sebas Avatar answered Nov 02 '22 02:11

Sebas