Skip to content
Advertisement

Get most common value in column [closed]

I have next table:

id value
 1 2
 2 4
 3 2
 4 2
 5 3

How I can get most common (common means that the count of 2 is 3, count of 4 is 1 and count of 3 is 1, so common is 2) ‘value’? in this case it is ‘2’?

Advertisement

Answer

you can use group by

select value
from the_table
group by value
order by count(*) desc
limit 1
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement