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

Re: Counting distinct rows

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: John Taylor <postgres(at)jtresponse(dot)co(dot)uk>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Counting distinct rows
Date: 2002-01-16 17:10:32
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

select id, count(*) from basketupdates group by id order by id desc;

On Wednesday 16 January 2002 02:38, John Taylor wrote:
> Hi,
> 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 ?
> Thanks
> JohnT
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

In response to

pgsql-novice by date

Next:From: Doug RoyerDate: 2002-01-16 20:57:04
Subject: Re: [ANNOUNCE] Commercial: New Book!! PostgreSQL book is
Previous:From: Jules AlbertsDate: 2002-01-16 13:31:24
Subject: Vim syntaxfile

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