Find duplicate records in MySQL

后端 未结 23 2886
别跟我提以往
别跟我提以往 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-22 00:04

    Another solution would be to use table aliases, like so:

    SELECT p1.id, p2.id, p1.address
    FROM list AS p1, list AS p2
    WHERE p1.address = p2.address
    AND p1.id != p2.id
    

    All you're really doing in this case is taking the original list table, creating two pretend tables -- p1 and p2 -- out of that, and then performing a join on the address column (line 3). The 4th line makes sure that the same record doesn't show up multiple times in your set of results ("duplicate duplicates").

提交回复
热议问题