Harry Pethel
Harry Pethel

Reputation: 9

How to only return unique values?

Say I have a table, and my column is account ID. My values are:

1
1
2
3
3
3
4
4

How would I phrase my query so it only returns the value that appears once, in this case 2? Any help appreciated!

attempting crafting query based on these instrcutions with no success: https://www.sqlservercentral.com/forums/topic/find-all-rows-where-the-value-in-one-column-only-occurs-once

Upvotes: -3

Views: 102

Answers (2)

Stu
Stu

Reputation: 32614

This looks like a simple aggregation:

select Id
from t
group by Id
having count(*) = 1;

Upvotes: 3

Sergey
Sergey

Reputation: 5225

SELECT A.ACCOUNT_ID
FROM YOUR_TABLE AS A
GROUP BY A.ACCOUNT_ID
HAVING COUNT(A.ACCOUNT_ID)=1

Upvotes: 3

Related Questions