
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Duplicate Column Values in MySQL
For this, use GROUP BY HAVING clause. Let us first create a table −
mysql> create table DemoTable1858 ( ModelNumber varchar(50) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1858 values('Audi A4'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi A6'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi A4'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi Q5'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi R8'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1858 values('Audi Q5'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1858;
This will produce the following output −
+-------------+ | ModelNumber | +-------------+ | Audi A4 | | Audi A6 | | Audi A4 | | Audi Q5 | | Audi R8 | | Audi Q5 | +-------------+ 6 rows in set (0.00 sec)
Here is the query to find duplicate column value in MySQL −
mysql> select ModelNumber from DemoTable1858 group by ModelNumber having count(ModelNumber) >=2;
This will produce the following output −
+-------------+ | ModelNumber | +-------------+ | Audi A4 | | Audi Q5 | +-------------+ 2 rows in set (0.00 sec)
Advertisements