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

From: "tjk(at)tksoft(dot)com" <tjk(at)tksoft(dot)com>
To: drew(at)albatross(dot)co(dot)nz (Drew Whittle)
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Counting the number of distinct rows returned
Date: 1999-08-19 05:20:36
Message-ID: 199908190520.WAA20898@uno.tksoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Drew,

Not really the answer you were asking, but in general, your
program will probably be using some interface other than
psql, i.e. libpq or Pg.pm, or whatever.

E.g. in C, if your PgQuery struct is pg1, then you
would do your query and retrieve the number of records
found with "pg1->PQntuples(pg1->reply)"

Troy

>
> 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
>
>
>
> ************
> Check out "PostgreSQL Wearables" @ http://www.pgsql.com
>
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jon Bundesen 1999-08-19 11:23:33 What JDBC datatype can be used for DATETIME ?
Previous Message Doug Younger 1999-08-19 02:10:35 Problems using count() with a join