
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to count number of duplicate values in a table column
Let us first create a table −
mysql> create table DemoTable( Data int ); Query OK, 0 rows affected (0.98 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(60); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(50); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(60); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(80); 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 −
+------+ | Data | +------+ | 60 | | 40 | | 50 | | 60 | | 40 | | 80 | +------+ 6 rows in set (0.00 sec)
Following is the query to count the number of duplicate values in a column −
mysql> select count(*) from DemoTable group by Data having count(Data) > 1;
This will produce the following output −
+----------+ | count(*) | +----------+ | 2 | | 2 | +----------+ 2 rows in set (0.03 sec)
- Related Articles
- MySQL query to count the duplicate ID values and display the result in a separate column
- Get the count of duplicate values from a single column in MySQL?
- How can we count a number of unique values in a column in MySQL table?
- MySQL query to display the count of distinct records from a column with duplicate records
- How do we count the total duplicate records in a column of MySQL table?
- Write a SQL query to count the number of duplicate TRANSACTION_ID in an ORDERS DB2 table
- MySQL query to fetch the maximum corresponding value from duplicate column values
- MySQL query to group results by date and display the count of duplicate values?
- Fetch specific rows from a MySQL table with duplicate column values (names)?
- How to use a single MySQL query to count column values ignoring null?
- MySQL query to get first two highest column values from a table?
- Get multiple count in a single MySQL query for specific column values
- How to get number of rows in a table without using count(*) MySQL query?
- MySQL query to display record with maximum count values in a group with other column values?
- MySQL query to count the number of 0s and 1s from a table column and display them in two columns?

Advertisements