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.
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 distinctlike 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 |
|
|
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. |
|
|
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, CustomerIdfrom Customergroup by grouping sets ((CustomerType), (CustomerReg), (CustomerId)) |
|
|
|
|
|