pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew J. Kopciuch <akopciuch@bddf.ca>
To: Mike Rylander <mrylander@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: sql
Date: Mon, 25 Oct 2004 05:44:06 -0600
Message-ID: <200410250544.06403.akopciuch@bddf.ca> (raw)
In-Reply-To: <b918cf3d041025042021ca123e@mail.gmail.com>
References: <013901c4ba6a$8771d320$7202a8c0@aaa>
	<b918cf3d041025042021ca123e@mail.gmail.com>

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 ...

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



view thread (20+ messages)  latest in thread

Message-ID: <200410250544.06403.akopciuch@bddf.ca>
Permalink:  ../200410250544.06403.akopciuch@bddf.ca/
Also on:    postgresql.org/message-id/200410250544.06403.akopciuch@bddf.ca

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: akopciuch@bddf.ca, mrylander@gmail.com
  Subject: Re: sql
  In-Reply-To: <200410250544.06403.akopciuch@bddf.ca>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox