Re: Counting distinct names

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "G(dot) Anthony Reina" <reina(at)nsi(dot)edu>
Cc: "pgsql-sql(at)postgreSQL(dot)org" <pgsql-sql(at)postgreSQL(dot)org>
Subject: Re: Counting distinct names
Date: 2000-04-18 03:25:36
Message-ID: 17170.956028336@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"G. Anthony Reina" <reina(at)nsi(dot)edu> writes:
> I'd like to find out how many times a unique 'subject_name' is in the
> table. My SQL book says that I should be able to do this:
> select COUNT(DISTINCT subject_name) from table1;
> However, the psql program is giving me an "ERROR: parser: parse error
> at or near "distinct"".

6.5 doesn't have aggregate(DISTINCT ...). 7.0 does, though.

If you don't want to upgrade right now, you could do something like

SELECT DISTINCT subject_name INTO temp_table FROM table1;
SELECT count(*) FROM temp_table;
DROP TABLE temp_table;

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Alexander Stetsenko 2000-04-18 08:13:49 trouble with null
Previous Message Brett W. McCoy 2000-04-18 02:16:09 Re: Counting distinct names