/ Published in: MySQL
URL: http://stackoverflow.com/questions/3501265/mysql-select-to-find-duplicates
Expand |
Embed | Plain Text
SELECT t1.name, t1.street, t1.house, GROUP_CONCAT(DISTINCT t1.id) dupes FROM your_table t1 JOIN your_table t2 ON (t2.name = t1.name AND t2.street = t1.street AND t2.house = t1.house) GROUP BY t1.name, t1.street, t1.house HAVING COUNT(*) > 1; CREATE TABLE your_table ( id INT, name VARCHAR(10), street VARCHAR(10), house VARCHAR(10) ); INSERT INTO your_table VALUES (1, 'a', 'b', 'c'); INSERT INTO your_table VALUES (2, 'a', '1', 'c'); INSERT INTO your_table VALUES (3, 'a', '2', '3'); INSERT INTO your_table VALUES (4, 'a', 'b', 'c'); INSERT INTO your_table VALUES (5, 'a', 'b', 'c'); INSERT INTO your_table VALUES (6, 'c', 'd', 'e'); INSERT INTO your_table VALUES (7, 'c', 'd', 'e'); +------+--------+-------+-------+ | name | street | house | dupes | +------+--------+-------+-------+ | a | b | c | 1,5,4 | | c | d | e | 6,7 | +------+--------+-------+-------+ 2 rows IN SET (0.03 sec)
You need to login to post a comment.
