Re: sql - Mailing list pgsql-sql

From Mike Rylander
Subject Re: sql
Date
Msg-id b918cf3d04102506056ead8820@mail.gmail.com
Whole thread Raw
In response to Re: sql  ("Andrew J. Kopciuch" <akopciuch@bddf.ca>)
List pgsql-sql
On Mon, 25 Oct 2004 05:44:06 -0600, Andrew J. Kopciuch
<akopciuch@bddf.ca> wrote:
> On Monday 25 October 2004 05:20, Mike Rylander wrote:
> > SELECT * FROM temp50 GROUP BY gc ORDER BY ora DESC;
> 
> You can not have have expressions (columns etc.) in the SELECT list that are
> either not in a GROUP BY clause, or used in an aggregate function when you
> use GROUP BY in the statement.  By saying SELECT *, means you would have to
> GROUP BY gc, co, data, ora ...

Doh!  Of course.   Should have had coffee before writing that ;)

> 
> That isn't going to do what he wants.  And the SQL you stated should give you
> an error:
> 
> ERROR:  column "temp50.co" must appear in the GROUP BY clause or be used in an
> aggregate function
> 
> What he wants to do is use DISTINCT ON:
> 
> SELECT DISTINCT ON (gc) gc, co, data, ora FROM temp50 ORDER BY gc, ora DESC;
> 
> Andy
>


pgsql-sql by date:

Previous
From: "Andrew J. Kopciuch"
Date:
Subject: Re: sql
Next
From: Gifford Hesketh
Date:
Subject: "copy from" in "create function"