Re: Counting Distinct Records - Mailing list pgsql-sql

From Thomas F.O'Connell
Subject Re: Counting Distinct Records
Date
Msg-id 6E79C2FE-380B-11D9-95C2-000D93AE0944@sitening.com
Whole thread Raw
In response to Re: Counting Distinct Records  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Responses Re: Counting Distinct Records  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
List pgsql-sql
Is there another way to accomplish what the former is doing, then?

For practical reasons, I'd like to come up with something better.

For theoretical curiosity, I'd like to know whether there's a way to 
combine COUNT and DISTINCT that still allows one to reference * rather 
than naming specific columns without grouping.

If I resort to GROUP BY, is there an efficient way of counting all the 
groups, or would it just be something like:

SELECT COUNT ( * ) FROM ( SELECT ... GROUP BY ... );

-tfo

--
Thomas F. O'Connell
Co-Founder, Information Architect
Sitening, LLC
http://www.sitening.com/
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-260-0005

On Nov 16, 2004, at 2:03 PM, Stephan Szabo wrote:

> On Tue, 16 Nov 2004, Thomas F.O'Connell wrote:
>
>> I am wondering whether the following two forms of SELECT statements 
>> are
>> logically equivalent:
>>
>> SELECT COUNT( DISTINCT table.column ) ...
>>
>> and
>>
>> SELECT DISTINCT COUNT( * ) ...
>
> Not in general.
>
> The former counts how many distinct table.column values there are.  The
> distinct in the latter would be basically meaningless unless there's a
> group by involved.
>



pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Counting Distinct Records
Next
From: Matt Nuzum
Date:
Subject: finding gaps in dates