Re: Counting Distinct Records

From: Thomas F(dot)O'Connell <tfo(at)sitening(dot)com>
To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
Cc: PgSQL - SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Counting Distinct Records
Date: 2004-11-16 20:09:33
Message-ID: 6E79C2FE-380B-11D9-95C2-000D93AE0944@sitening.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Matt Nuzum 2004-11-16 20:56:31 finding gaps in dates
Previous Message Stephan Szabo 2004-11-16 20:03:35 Re: Counting Distinct Records