Mysql select only unique rows (that appears only one time)

时间:2017-03-02 23:41:54

标签: php mysql

Consider following data in table ->

1   example@hotmail.com
2   example12@hotmail.com
3   example@hotmail.com
4   example@hotmail.com

I want it to return only the following:

2   example12@hotmail.com

...and skip the duplicate values.

2 个答案:

答案 0 :(得分:2)

The query you want is

SELECT id, email, whatEverColumn 
FROM table 
WHERE email IN (SELECT email 
               FROM table 
               GROUP BY email 
               HAVING COUNT(id) = 1)

答案 1 :(得分:2)

Group by email and add having count(email) = 1