deltanovember
deltanovember

Reputation: 44051

How do I extract unique values from SQL?

For example suppose I have the following table

user_id, score
1,5
1,4
2,9
3,7
3,6
3,15
4,8
4,11

I want a query that returns user_id 2 because it is the only user_id that is not repeated

Upvotes: 2

Views: 445

Answers (3)

ziu
ziu

Reputation: 2720

SELECT user_id 
FROM table
GROUP BY user_id
HAVING (COUNT(user_id)=1)

Upvotes: 0

codaddict
codaddict

Reputation: 454980

select user_id 
from tableName
group by user_id 
having count(*)  = 1;

Upvotes: 1

Ocaso Protal
Ocaso Protal

Reputation: 20234

SELECT user_id FROM table GROUP BY(user_id) HAVING COUNT(user_id) = 1

Upvotes: 7

Related Questions