How to only return unique values?

69 views Asked by At

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

2

There are 2 answers

0
Sergey On
SELECT A.ACCOUNT_ID
FROM YOUR_TABLE AS A
GROUP BY A.ACCOUNT_ID
HAVING COUNT(A.ACCOUNT_ID)=1
0
Stu On

This looks like a simple aggregation:

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