Reputation: 35
I have following SQL table:
+--------------+
| Account |
+--------------+
| 11100011 |
| 11100012 |
| 11100013 |
| 11100014 |
| 11100011 |
| 11100012 |
| 11100015 |
+--------------+
What I need is to make a select query with rows that do not have any duplicates in this table (i.e. removing both duplicated rows), so query result will look like this
+--------------+
| Account |
+--------------+
| 11100013 |
| 11100014 |
| 11100015 |
+--------------+
How can I do this in tsql?
Upvotes: 0
Views: 57
Reputation: 2516
Using Window Function also we get the same result
SELECT Account FROM
(
SELECT Account,
COUNT(Account)OVER(Partition by Account ORDER BY Account) AS DistinctCnt
FROM cte
)
DT WHERE DT.DistinctCnt=1
Result
Account
--------
11100013
11100014
11100015
Upvotes: 0
Reputation: 48
Try this,
select * from table_name group by account having count(*)<=1;
Upvotes: 1
Reputation: 28890
select account
from
table
group by account
having count(*)=1
Upvotes: 5
Reputation: 1203
SELECT DISTINCT Account
FROM table_name_in_your_database;
General this query is used for selecting distinct elements in the table.
Upvotes: 1