Skip site navigation (1) Skip section navigation (2)

Counting distinct rows

From: John Taylor <postgres(at)jtresponse(dot)co(dot)uk>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Counting distinct rows
Date: 2002-01-16 10:38:12
Message-ID: (view raw or whole thread)
Lists: pgsql-novice

I'm having problems counting the number of distinct rows in a table.

I've tried the following:

	select distinct on(id) count(id)  from basketupdates order by id desc; 

but I get the error

	ERROR:  Attribute must be GROUPed or used in an aggregate function

I think it should say "MUST NOT", as if I remove the aggregate it works fine. 
So I don't think this is the way to go about it.

Can anyone tell how I should be going about counting the distinct ids in a table ?



pgsql-novice by date

Next:From: Oliver ElphickDate: 2002-01-16 10:44:26
Subject: Re: select !working
Previous:From: denisDate: 2002-01-16 05:29:07
Subject: select !working

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group