- 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
Get the count of duplicate values from a single column in MySQL?
Let us first create a table −
mysql> create table DemoTable -> ( -> Number int -> ); Query OK, 0 rows affected (0.83 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+ | Number | +--------+ | 20 | | 20 | | 10 | | 30 | | 10 | | 10 | +--------+ 6 rows in set (0.00 sec)
Following is the query to select count values from a single column −
mysql> select Number,count(*) from DemoTable group by Number;
This will produce the following output −
+--------+----------+ | Number | count(*) | +--------+----------+ | 20 | 2 | | 10 | 3 | | 30 | 1 | +--------+----------+ 3 rows in set (0.00 sec)
- Related Articles
- Get multiple count in a single MySQL query for specific column values
- MySQL query to count number of duplicate values in a table column
- Get minimum value from a column (floating values) with corresponding duplicate ids in MySQL
- Display the count of duplicate records from a column in MySQL and order the result
- 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?
- Get count of values that only appear once in a MySQL column?
- MySQL query to count the duplicate ID values and display the result in a separate column
- Select minimum row value from a column with corresponding duplicate column values in MySQL
- Find and display duplicate values only once from a column in MySQL
- A single query to get the sum of count from different tables in MySQL?
- MySQL query to display the count of distinct records from a column with duplicate records
- Add records from corresponding duplicate values in another column with MySQL
- How to use a single MySQL query to count column values ignoring null?
- Count NOT NULL values from separate tables in a single MySQL query

Advertisements