
- 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
Find and display duplicate values only once from a column in MySQL
Let us first create a table −
mysql> create table DemoTable -> ( -> value int -> ); Query OK, 0 rows affected (0.82 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.07 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+-------+ | value | +-------+ | 10 | | 100 | | 20 | | 10 | | 30 | | 40 | | 20 | +-------+ 7 rows in set (0.00 sec)
Following is the query to find the duplicate values and display them once −
mysql> select *from DemoTable group by value having count(*) > 1;
Output
This will produce the following output −
+-------+ | value | +-------+ | 10 | | 20 | +-------+ 2 rows in set (0.00 sec)
- Related Articles
- Select a value from MySQL database only if it exists only once from a column with duplicate and non-duplicate values
- How to order return duplicate column values only once in MySQL?
- Find duplicate column values in MySQL and display them
- Python – Display only non-duplicate values from a DataFrame
- Get count of values that only appear once in a MySQL column?
- Display only the duplicate column names appearing atleast thrice in MySQL
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL
- GROUP BY and display only non-empty column values in MySQL
- Display only a specific duplicate record in MySQL
- Python Pandas – Create a subset and display only the last entry from duplicate values
- MySQL query to count the duplicate ID values and display the result in a separate column
- Display matching repeated date records only once in MySQL
- MySQL select only duplicate records from database and display the count as well?
- Find and display duplicate records in MySQL?
- Select minimum row value from a column with corresponding duplicate column values in MySQL

Advertisements