dbTalk Databases Forums  

count multiple distinct columns

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss count multiple distinct columns in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dean
 
Posts: n/a

Default count multiple distinct columns - 07-13-2004 , 05:35 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.



Reply With Quote
  #2  
Old   
Dan Guzman
 
Posts: n/a

Default Re: count multiple distinct columns - 07-13-2004 , 06:54 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

"Dean" <noreply (AT) fakeaddress (DOT) com> wrote

Quote:
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.





Reply With Quote
  #3  
Old   
Dean
 
Posts: n/a

Default Re: count multiple distinct columns - 07-13-2004 , 07:00 PM



"Dan Guzman" <danguzman (AT) nospam-earthlink (DOT) net> wrote

Quote:
One method is to use a derived table:

SELECT COUNT(*)
FROM (
SELECT DISTINCT c1, c2
FROM t1) AS t1
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.




Reply With Quote
  #4  
Old   
JK
 
Posts: n/a

Default Re: count multiple distinct columns - 07-14-2004 , 01:19 AM



Try this out..

SELECT COUNT(*) FROM (select distinct c1, c2 from t1)T

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.