pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: D'Arcy J.M. Cain <darcy@druid.net>
To: Joel Richard <postgres@joelrichard.com>
Cc: Claudia Kosny <ckosny@gmx.net>
Cc: sql pgsql <pgsql-sql@postgresql.org>
Subject: Re: fetch first rows of grouped data
Date: Mon, 27 Aug 2007 14:15:52 -0400
Message-ID: <20070827141552.21ec3a54.darcy@druid.net> (raw)
In-Reply-To: <4CB5D209-C0CC-466E-A967-E766D6AD799B@joelrichard.com>
References: <46D2FD9F.3020000@gmx.net>
	<20070827125102.e52b43de.darcy@druid.net>
	<4CB5D209-C0CC-466E-A967-E766D6AD799B@joelrichard.com>

On Mon, 27 Aug 2007 13:34:09 -0400
Joel Richard <postgres@joelrichard.com> wrote:
> That's what I thought at first, but this is not the case. She's  
> looking for the first two dates in -each- city in the table. I  
> initially thought that this could be accomplished with GROUP BY and  
> LIMIT, but GROUP BY can only give you the first date for each city,  
> not the first two dates for each city.

Yes, you are correct.  My mistake.

> So far, I haven't come up with any clever ideas. I'm not sure this  
> can be done in SQL.

Well, I can think of an SQL only method involving a temporary table but
it would not be a single query:

 - Select into temp table where date is max.
 - Select from temp table union with main table where date is max and
is not in temp table.

-- 
D'Arcy J.M. Cain <darcy@druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



view thread (9+ messages)  latest in thread

Message-ID: <20070827141552.21ec3a54.darcy@druid.net>
Permalink:  ../20070827141552.21ec3a54.darcy@druid.net/
Also on:    postgresql.org/message-id/20070827141552.21ec3a54.darcy@druid.net

 · 

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: darcy@druid.net, postgres@joelrichard.com, ckosny@gmx.net
  Subject: Re: fetch first rows of grouped data
  In-Reply-To: <20070827141552.21ec3a54.darcy@druid.net>

* 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