Skip site navigation (1) Skip section navigation (2)

Counting Distinct Records

From: Thomas F(dot)O'Connell <tfo(at)sitening(dot)com>
To: PgSQL - SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Counting Distinct Records
Date: 2004-11-16 19:45:45
Message-ID: 1B2F7B00-3808-11D9-95C2-000D93AE0944@sitening.com (view raw or flat)
Thread:
Lists: pgsql-sql
I am wondering whether the following two forms of SELECT statements are 
logically equivalent:

SELECT COUNT( DISTINCT table.column ) ...

and

SELECT DISTINCT COUNT( * ) ...

If they are the same, then why is the latter query much slower in 
postgres when applied to the same FROM and WHERE clauses?

Furthermore, is there a better way of performing this sort of operation 
in postgres (or just in SQL in general)?

Thanks!

-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


Responses

pgsql-sql by date

Next:From: Stephan SzaboDate: 2004-11-16 20:03:35
Subject: Re: Counting Distinct Records
Previous:From: Pierre-Frédéric CaillaudDate: 2004-11-16 18:51:31
Subject: Re: tree structure photo gallery date quiery

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group