Forum Moderators: open
I have a table of "users" now lets say i want to show all the rows that have duplicate email addresses, for example if there are mor then one rows having some email address both of them should be showin the the SQL output so i can check their userids. i dont want something like count and stuff, just want both rows to be shown in the output, for all email addresses that occur more then once in the rows of the table.
SELECT t1.keyfield, t1.email, t2.keyfield, t2.email
FROM table AS t1 INNER JOIN table AS t2 ON t1.email=t2.email
WHERE t1.keyfield<>t2.keyfield
The join joins the table to itself and produces every combination of rows where the emails match. The where clause then removes the rows that have matched themselves.