Re: field must appear in the GROUP BY clause or be used

From: "John Sidney-Woollett" <johnsw(at)wardbrook(dot)com>
To: "Bill Moran" <wmoran(at)potentialtech(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: field must appear in the GROUP BY clause or be used
Date: 2004-02-27 16:13:31
Message-ID: 3077.192.168.0.64.1077898411.squirrel@mercury.wardbrook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bill Moran said:
> I've hit an SQL problem that I'm a bit mystified by. I have two different
> questions regarding this problem: why? and how do I work around it?
>
> The following query:
>
> SELECT GCP.id,
> GCP.Name
> FROM Gov_Capital_Project GCP,
> WHERE TLM.TLI_ID = $2
> group by GCP.id
> ORDER BY gcp.name;
>
> Produces the following error:
>
> ERROR: column "gcp.name" must appear in the GROUP BY clause or be used in
> an aggregate function

Since you're not agregating data, can't you use a select distinct instead?

SELECT distinct GCP.id, GCP.Name
FROM Gov_Capital_Project GCP, {?something missing here?}
WHERE TLM.TLI_ID = $2
ORDER BY gcp.name;

(BTW, I wasn't clear if the where clause trying to join to another table?)

Doesn't answer your original question, but hope it helps anyway.

John Sidney-Woollett

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bill Moran 2004-02-27 16:31:32 Re: compartmentalizing users
Previous Message Ron St-Pierre 2004-02-27 16:11:31 Re: change db encoding