Re: [SQL] Counting the number of distinct rows returned

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Drew Whittle <drew(at)albatross(dot)co(dot)nz>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Counting the number of distinct rows returned
Date: 1999-08-19 13:18:33
Message-ID: 7811.935068713@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Drew Whittle <drew(at)albatross(dot)co(dot)nz> writes:
> How can I return the number of records (ie a count(user_id)) when using a
> statement like this:

> select distinct user_id from sales_by_region;

count() with a GROUP BY will do what you want, I think --- see other
thread with Doug Younger for an example.

> I have tried things like:
> select count(distinct user_id) from sales_by_region (parse error)

Unfortunately we don't handle count(distinct ...) --- we should, since
it's in SQL92.

regards, tom lane

Browse pgsql-sql by date

  From Date Subject
Next Message Sejin Oh 1999-08-19 13:56:50 Re: [SQL] Counting the number of distinct rows returned
Previous Message Dirk Lutzebaeck 1999-08-19 13:17:46 does LIMIT save time?