笑故挽风 2009-05-12 18:24 采纳率: 100%
浏览 363
已采纳

在 MySQL 中找到重复的记录

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 > 1

Which results in:

100 MAIN ST    2

I would like to pull it so that it shows each row that is a duplicate. Something like:

JIM    JONES    100 MAIN ST
JOHN   SMITH    100 MAIN ST

Any thoughts on how this can be done? I'm trying to avoid doing the first one then looking up the duplicates with a second query in the code.

转载于:https://stackoverflow.com/questions/854128/find-duplicate-records-in-mysql

  • 写回答

22条回答 默认 最新

  • 斗士狗 2009-05-12 18:33
    关注

    The key is to rewrite this query so that it can be used as a subquery.

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(21条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?