Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 multiple unique field values

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2014-12-15 : 17:21:58
Hi friends I have table from customer where in I want to get distinct values of its three columns CustomerType, CustomerReg,CustomerID.

Instead of doing three separate queries for the distinct

like select distinct CustomerType From Customer.. and then for CustomerReg..Can it be achieved in one query...

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-12-15 : 17:23:53
select distinct CustomerType, CustomerReg,CustomerID from Customer
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2014-12-15 : 18:43:39
You could use subqueries under a main/outer query. You could "join" on a generated row number to return all values in a single result set.
Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2014-12-15 : 23:32:37
quote:
Originally posted by ScottPletcher

You could use subqueries under a main/outer query. You could "join" on a generated row number to return all values in a single result set.


THis is how i could achieve it...

select CustomerType, CustomerReg, CustomerId
from Customer
group by grouping sets ((CustomerType), (CustomerReg), (CustomerId))
Go to Top of Page
   

- Advertisement -