Re: field must appear in the GROUP BY clause or be used - Mailing list pgsql-general

From John Sidney-Woollett
Subject Re: field must appear in the GROUP BY clause or be used
Date
Msg-id 3077.192.168.0.64.1077898411.squirrel@mercury.wardbrook.com
Whole thread Raw
In response to field must appear in the GROUP BY clause or be used in an aggregate function?  (Bill Moran <wmoran@potentialtech.com>)
Responses Re: field must appear in the GROUP BY clause or be used  (Bill Moran <wmoran@potentialtech.com>)
List 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


pgsql-general by date:

Previous
From: Ron St-Pierre
Date:
Subject: Re: change db encoding
Next
From: Bill Moran
Date:
Subject: Re: compartmentalizing users