0

我是这样做的:

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

有合约公式吗?

4

1 回答 1

1

如果您不想要 NULL 结果,请使用 INNER JOIN。

SELECT DISTINCT(u2.email) FROM users u1 
    INNER JOIN users u2 ON u1.email = u2.email AND u1.id <> u2.id

如果必须使用 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
于 2012-06-08T00:07:20.423 回答