我想提取 MySQL 数据库中的重复记录。这可以通过以下方式完成:
SELECT address, count(id) as cnt FROM list GROUP BY address HAVING cnt > 1
结果是:
100 MAIN ST 2
我想拉它,以便它显示重复的每一行。就像是:
JIM JONES 100 MAIN ST JOHN SMITH 100 MAIN ST
关于如何做到这一点的任何想法?我试图避免做第一个,然后在代码中使用第二个查询查找重复项。
关键是重写这个查询,以便它可以用作子查询。
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;