Re: FW: Count & Distinct

From: Nils Zonneveld <nils(at)casema(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: FW: Count & Distinct
Date: 2000-08-27 12:53:16
Message-ID: 39A90F24.D0CC8ECB@casema.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

anuj wrote:
>
> > >>> select count(distinct(row)) from table;
> hi,
> I have also tried but I am geting an error.
>

It's true that you get an error from trying to execute the query above;
'distinct' is not a function but a keyword, count() is a agregate
function. Following this the correct notation for your query would be:

select count(distinct <row>) from <table>;

I tested this on postgreSQL 7.02 and it works.

I tried this:

NAW=# \d tmpTable
Table "tmptable"
Attribute | Type | Modifier
-----------+-------------+----------
id | integer |
name | varchar(25) |

NAW=# select * from tmpTable;
id | name
----+-----------
1 | Jansen
2 | Jansen
3 | Pietersen
4 | Pietersen
(4 rows)

NAW=# select count(name) from tmpTable;
count
-------
4
(1 row)

NAW=# select count(distinct name) from tmpTable;
count
-------
2
(1 row)

Success and kind regards,

Nils Zonneveld
--
"Misschien is niets geheel waar, en zelfs dat niet"
Multatuli (Eduard Douwes Dekker) - Idee 1

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Miles Thompson 2000-08-27 14:09:21 Re: table count limitation
Previous Message Marcin Inkielman 2000-08-27 09:34:51 Re: table count limitation