Find most frequent value in SQL column code example

Example 1: sql select most frequent value in column

SELECT col, COUNT(col) AS value_occurrence
FROM m_table GROUP BY col ORDER BY value_occurrence DESC LIMIT 1;

-- Oracle <= 11g
SELECT * FROM (SELECT col, COUNT(col) AS value_occurrence
FROM m_table GROUP BY col ORDER BY value_occurrence DESC)
WHERE rownum = 1;

Example 2: Find most frequent value in SQL column

SELECT       `column`,
             COUNT(`column`) AS `value_occurrence` 
    FROM     `my_table`
    GROUP BY `column`
    ORDER BY `value_occurrence` DESC
    LIMIT    1;

Tags:

Sql Example