Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find duplicates in the same table in MySQL

Tags:

I have a table with two columns - artist, release_id

What query can I run to show duplicate records?

e.g. my table is

ArtistX : 45677 ArtistY : 378798 ArtistX : 45677 ArtistZ : 123456 ArtistY : 888888 ArtistX : 2312 ArtistY: 378798 

The query should show

ArtistX : 45677 ArtistX : 45677 ArtistY : 378798 ArtistY : 378798 
like image 890
Franco Avatar asked Feb 11 '12 11:02

Franco


People also ask

How do I find duplicate records in the same table in MySQL?

Find Duplicate Row values in One ColumnSELECT col, COUNT(col) FROM table_name GROUP BY col HAVING COUNT(col) > 1; In the above query, we do a GROUP BY for the column for which we want to check duplicates. We also use a COUNT() and HAVING clause to get the row counts for each group.

How do I find duplicate names in a table in SQL?

To find the duplicate Names in the table, we have to follow these steps: Defining the criteria: At first, you need to define the criteria for finding the duplicate Names. You might want to search in a single column or more than that. Write the query: Then simply write the query to find the duplicate Names.


1 Answers

You can use a grouping across the columns of interest to work out if there are duplicates.

SELECT     artist, release_id, count(*) no_of_records FROM table GROUP BY artist, release_id HAVING count(*) > 1; 
like image 155
a'r Avatar answered Nov 15 '22 22:11

a'r