Groups | Blog | Home
all groups > sql server (alternate) > july 2004 >

sql server (alternate) : count multiple distinct columns


Dean
7/13/2004 3:35:17 PM
I want to build query to return how many rows are in this query:
select distinct c1, c2 from t1

But SQL won't accept this syntax:
select count (distinct c1, c2) from t1

Does someone know how to count multiple distinct columns? Thanks.



--
Disclaimer: This post is solely an individual opinion and does not speak on
behalf of any organization.

Dean
7/13/2004 5:00:01 PM
[quoted text, click to view]

Thanks! I was trying
SELECT COUNT(*) FROM (SELECT DISTINCT c1, c2 FROM t1)
but it wouldn't work without the "AS t1" at the end.

--
Disclaimer: This post is solely an individual opinion and does not speak on
behalf of any organization.

jaikrishnan_nair NO[at]SPAM hotmail.com
7/13/2004 11:19:17 PM
Try this out..

Dan Guzman
7/13/2004 11:54:44 PM
One method is to use a derived table:

SELECT COUNT(*)
FROM (
SELECT DISTINCT c1, c2
FROM t1) AS t1

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]

AddThis Social Bookmark Button