Wednesday, February 1, 2012

find duplicated records

SELECT id, email, count(email) FROM users GROUP BY email HAVING count(email) > 1

self join
SELECT DISTINCT t1.id, t1.email FROM users t1, users t2 WHERE t1.email = t2.email AND t1.id <> t2.id

--
select id, count(*) as number_records
from table
group by id having count(*)>1

No comments:

Post a Comment