Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

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

1 Answer

0 votes
by (40.7k points)

Try using the below code:

SELECT       `column`,

             COUNT(`column`) AS `value_occurrence` 

    FROM     `my_table`

    GROUP BY `column`

    ORDER BY `value_occurrence` DESC

    LIMIT    1;

Note: You can replace the column and my_table. You can also increase 1 if you want to see the N most common values of the column.

Enroll yourself in the SQL server certification to learn in-depth about SQL statements, queries and become proficient in SQL.

Related questions

0 votes
1 answer
+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...