Johny Pie
Johny Pie

Reputation: 843

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

Consider following data in table ->

1   [email protected]
2   [email protected]
3   [email protected]
4   [email protected]

I want it to return only the following:

2   [email protected]

...and skip the duplicate values.

Upvotes: 1

Views: 499

Answers (2)

Kyoya
Kyoya

Reputation: 343

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)

Upvotes: 2

vadim
vadim

Reputation: 176

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

Upvotes: 2

Related Questions