Find duplicates in the same table in MySQL

后端 未结 13 1875
感动是毒
感动是毒 2020-12-10 02:03

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         


        
相关标签:
13条回答
  • 2020-12-10 02:04

    you can use this query for the same result. it works for me

    SELECT firstname, lastname, list.address FROM list
    INNER JOIN (SELECT address FROM list
    GROUP BY address HAVING count(id) > 1) dup ON list.address = dup.address
    
    0 讨论(0)
  • 2020-12-10 02:05

    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;
    
    0 讨论(0)
  • 2020-12-10 02:05
    SELECT artist, count(*) 
    FROM tableName 
    GROUP BY artist 
    HAVING count(*) > 1;
    
    0 讨论(0)
  • 2020-12-10 02:07
    SELECT id,artist,COUNT(id) as found FROM table GROUP by id HAVING found > 1
    
    0 讨论(0)
  • 2020-12-10 02:08

    SELECT artist, release_id, count(*) no_of_records, group_concat(id) FROM table GROUP BY artist, release_id HAVING count(*) > 1;

    also adding group_concat(id) gets you all ids of the duplicates.

    0 讨论(0)
  • 2020-12-10 02:08

    Try this:

    SELECT A.ARTIST,A.RELEASE_ID FROM ARTISTS A
    WHERE EXISTS(
    SELECT 'X' FROM ARTISTS B
    WHERE B.ARTIST = A.ARTIST AND B.RELEASE_ID = A.RELEASE_ID
    GROUP BY B.ARTIST,B.RELEASE_ID
    HAVING COUNT(B.ARTIST)>1)
    ORDER BY A.ARTIST;
    
    0 讨论(0)
提交回复
热议问题