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.
This also will show you how many duplicates have and will order the results without joins
select address from list where address = any (select address from (select address, count(id) cnt from list group by address having cnt > 1 ) as t1) order by address
the inner sub-query returns rows with duplicate address then the outer sub-query returns the address column for address with duplicates. the outer sub-query must return only one column because it used as operand for the operator '= any'
This is the similar query you have asked for and its 200% working and easy too. Enjoy!!!
Find duplicate users by email address with this query...
Not going to be very efficient, but it should work:
For your table it would be something like
This query will give you all the distinct address entries in your list table... I am not sure how this will work if you have any primary key values for name, etc..