Reputation: 3161
I done in that way:
SELECT * FROM (
SELECT DISTINCT (u2.email) email FROM `users` u1 LEFT JOIN
users u2 ON u1.email = u2.email AND u1.id <> u2.id
)users WHERE email IS NOT NULL
Is there a contract formula?
Upvotes: 0
Views: 856
Reputation: 2312
Use an INNER JOIN if you don't want NULL results.
SELECT DISTINCT(u2.email) FROM users u1
INNER JOIN users u2 ON u1.email = u2.email AND u1.id <> u2.id
If you must use a LEFT JOIN:
SELECT DISTINCT(u2.email) FROM users u1
LEFT JOIN users u2 ON u1.email = u2.email AND u1.id <> u2.id
WHERE u2.email IS NOT NULL
Upvotes: 1