- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Count top 10 most occurring values in a column in MySQL?
To count the top 10 most occurring values in a column in MySQL, The syntax is as follows −
SELECT yourColumnName, count(*) FROM yourTableName GROUP BY yourColumnName ORDER BY count(*) DESC LIMIT 10;
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table countTop10Demo -> ( -> Value int -> ); Query OK, 0 rows affected (0.74 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into countTop10Demo values(10); Query OK, 1 row affected (0.12 sec) mysql> insert into countTop10Demo values(1100); Query OK, 1 row affected (0.11 sec) mysql> insert into countTop10Demo values(200); Query OK, 1 row affected (0.11 sec) mysql> insert into countTop10Demo values(2100); Query OK, 1 row affected (0.10 sec) mysql> insert into countTop10Demo values(1100); Query OK, 1 row affected (0.11 sec) mysql> insert into countTop10Demo values(450); Query OK, 1 row affected (0.28 sec) mysql> insert into countTop10Demo values(600); Query OK, 1 row affected (0.12 sec) mysql> insert into countTop10Demo values(2100); Query OK, 1 row affected (0.16 sec) mysql> insert into countTop10Demo values(150); Query OK, 1 row affected (0.16 sec) mysql> insert into countTop10Demo values(16454); Query OK, 1 row affected (0.10 sec) mysql> insert into countTop10Demo values(450); Query OK, 1 row affected (0.12 sec) mysql> insert into countTop10Demo values(2350); Query OK, 1 row affected (0.10 sec) mysql> insert into countTop10Demo values(1780); Query OK, 1 row affected (0.15 sec) mysql> insert into countTop10Demo values(1345); Query OK, 1 row affected (0.22 sec) mysql> insert into countTop10Demo values(34); Query OK, 1 row affected (0.15 sec) mysql> insert into countTop10Demo values(2100); Query OK, 1 row affected (0.08 sec) mysql> insert into countTop10Demo values(19034); Query OK, 1 row affected (0.12 sec) mysql> insert into countTop10Demo values(1844); Query OK, 1 row affected (0.11 sec) mysql> insert into countTop10Demo values(34); Query OK, 1 row affected (0.08 sec) mysql> insert into countTop10Demo values(16454); Query OK, 1 row affected (0.19 sec)
Now you can Display all records from the table using select statement. The query is as follows −
mysql> select *from countTop10Demo;
Here is the output −
+-------+ | Value | +-------+ | 10 | | 1100 | | 200 | | 2100 | | 1100 | | 450 | | 600 | | 2100 | | 150 | | 16454 | | 450 | | 2350 | | 1780 | | 1345 | | 34 | | 2100 | | 19034 | | 1844 | | 34 | | 16454 | +-------+ 20 rows in set (0.00 sec)
The following is the query to select top 10 most occurring values in a column in MySQL −
mysql> SELECT Value, count(*) -> FROM countTop10Demo -> GROUP BY Value -> ORDER BY count(*) DESC -> LIMIT 10;
Here is the output −
+-------+----------+ | Value | count(*) | +-------+----------+ | 2100 | 3 | | 1100 | 2 | | 34 | 2 | | 450 | 2 | | 16454 | 2 | | 1780 | 1 | | 200 | 1 | | 1345 | 1 | | 19034 | 1 | | 600 | 1 | +-------+----------+ 10 rows in set (0.00 sec)
- Related Articles
- Get the count of the most frequently occurring values in MySQL?
- Selecting the top occurring entries in MySQL from a table with duplicate values?
- Finding top three most occurring words in a string of text in JavaScript
- Count substrings with each character occurring at most k times in C++
- Python program to find the most occurring character and its count
- Get the count of duplicate values from a single column in MySQL?
- Get count of values that only appear once in a MySQL column?
- MySQL query to count number of duplicate values in a table column
- Get multiple count in a single MySQL query for specific column values
- Top 10 Most Effective Business Analysis Techniques
- Get the maximum count of distinct values in a separate column with MySQL
- Can I get the count of repeated values in a column with MySQL?
- How can we count a number of unique values in a column in MySQL table?
- MySQL query to display record with maximum count values in a group with other column values?
- The most occurring number in a string using Regex in python

Advertisements