pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas F.O'Connell <tfo@sitening.com>
To: Stephan Szabo <sszabo@megazone.bigpanda.com>
Cc: PgSQL - SQL <pgsql-sql@postgresql.org>
Subject: Re: Counting Distinct Records
Date: Tue, 16 Nov 2004 14:09:33 -0600
Message-ID: <6E79C2FE-380B-11D9-95C2-000D93AE0944@sitening.com> (raw)
In-Reply-To: <20041116115807.E79990@megazone.bigpanda.com>
References: <1B2F7B00-3808-11D9-95C2-000D93AE0944@sitening.com>
	<20041116115807.E79990@megazone.bigpanda.com>

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




view thread (7+ messages)  latest in thread

Message-ID: <6E79C2FE-380B-11D9-95C2-000D93AE0944@sitening.com>
Permalink:  ../6E79C2FE-380B-11D9-95C2-000D93AE0944@sitening.com/
Also on:    postgresql.org/message-id/6E79C2FE-380B-11D9-95C2-000D93AE0944@sitening.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tfo@sitening.com, sszabo@megazone.bigpanda.com
  Subject: Re: Counting Distinct Records
  In-Reply-To: <6E79C2FE-380B-11D9-95C2-000D93AE0944@sitening.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox