Counting the number of distinct rows returned

From: Drew Whittle <drew(at)albatross(dot)co(dot)nz>
To: pgsql-sql(at)postgreSQL(dot)org
Subject: Counting the number of distinct rows returned
Date: 1999-08-18 23:59:21
Message-ID: 4.1.19990819115506.00cfd890@pern.csarc.otago.ac.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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;

I have tried things like:

select count(distinct user_id) from sales_by_region (parse error)
select distinct count(user_id) from sales_by_region (useless because count
is performed before the distinct)

HELP!

Thanks,

Drew

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Doug Younger 1999-08-19 02:10:35 Problems using count() with a join
Previous Message Bruce Momjian 1999-08-18 15:10:38 Re: [SQL] Using intersect in subquery