Find most frequent value in SQL column

Jake picture Jake · Sep 2, 2012 · Viewed 224.9k times · Source

How can I find the most frequent value in a given column in an SQL table?

For example, for this table it should return two since it is the most frequent value:

one
two
two
three

Answer

Mihai Stancu picture Mihai Stancu · Sep 2, 2012
SELECT       `column`,
             COUNT(`column`) AS `value_occurrence` 
    FROM     `my_table`
    GROUP BY `column`
    ORDER BY `value_occurrence` DESC
    LIMIT    1;

Replace column and my_table. Increase 1 if you want to see the N most common values of the column.