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 |
cindylee
Yak Posting Veteran
55 Posts |
Posted - 2005-03-13 : 23:05:44
|
Hi guysi need to get count of few distinct columns in my table.the following query works fine (only when one column is specified)select count(distinct x)from tblxbut i want to look for more than one column in distinct..someting like thisselect count(distinct x,y,z,d)from tblxgetting following error:Server: Msg 170, Level 15, State 1, Line 1Line 1: Incorrect syntax near ','.Any help greatly appreciatedcindy |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2005-03-14 : 00:09:57
|
[code]select count(distinct x), count(distinct y), count(distinct z), count(distinct d)from tblx[/code]CODO ERGO SUM |
|
|
cindylee
Yak Posting Veteran
55 Posts |
Posted - 2005-03-14 : 17:49:53
|
Thanksbut i just want one count result.I dont think we can get a total count for more than one distinct column(s)Thankscindy |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-03-14 : 17:53:02
|
[code]SELECT COUNT(*)FROM( SELECT DISTINCT Column1, Column2 FROM @Table1) t[/code]Tara |
|
|
cindylee
Yak Posting Veteran
55 Posts |
Posted - 2005-03-14 : 21:59:37
|
Well Now,, "THAT IS THINKING"Thanks tara, it works greatCindy |
|
|
dmorris
Starting Member
1 Post |
Posted - 2014-03-04 : 09:20:53
|
Another option is to concatenate multiple columns in your count expressioncount(distinct cast(col0 as varchar) + '.' + cast(col1 as varchar)) as unique_col0_and_col1I don't think this is better than using a sub query. |
|
|
|
|
|
|
|