Find duplicate records in MySQL

后端 未结 23 2847
别跟我提以往
别跟我提以往 2020-11-21 23:12

I want to pull out duplicate records in a MySQL Database. This can be done with:

SELECT address, count(id) as cnt FROM list
GROUP BY address HAVING cnt >         


        
相关标签:
23条回答
  • 2020-11-21 23:55

    Not going to be very efficient, but it should work:

    SELECT *
    FROM list AS outer
    WHERE (SELECT COUNT(*)
            FROM list AS inner
            WHERE inner.address = outer.address) > 1;
    
    0 讨论(0)
  • 2020-11-21 23:56

    Fastest duplicates removal queries procedure:

    /* create temp table with one primary column id */
    INSERT INTO temp(id) SELECT MIN(id) FROM list GROUP BY (isbn) HAVING COUNT(*)>1;
    DELETE FROM list WHERE id IN (SELECT id FROM temp);
    DELETE FROM temp;
    
    0 讨论(0)
  • 2020-11-21 23:58

    Find duplicate users by email address with this query...

    SELECT users.name, users.uid, users.mail, from_unixtime(created)
    FROM users
    INNER JOIN (
      SELECT mail
      FROM users
      GROUP BY mail
      HAVING count(mail) > 1
    ) dupes ON users.mail = dupes.mail
    ORDER BY users.mail;
    
    0 讨论(0)
  • 2020-11-21 23:59

    Isn't this easier :

    SELECT *
    FROM tc_tariff_groups
    GROUP BY group_id
    HAVING COUNT(group_id) >1
    

    ?

    0 讨论(0)
  • 2020-11-22 00:00

    This also will show you how many duplicates have and will order the results without joins

    SELECT  `Language` , id, COUNT( id ) AS how_many
    FROM  `languages` 
    GROUP BY  `Language` 
    HAVING how_many >=2
    ORDER BY how_many DESC
    
    0 讨论(0)
  • 2020-11-22 00:02
        SELECT *
        FROM (SELECT  address, COUNT(id) AS cnt
        FROM list
        GROUP BY address
        HAVING ( COUNT(id) > 1 ))
    
    0 讨论(0)
提交回复
热议问题