Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id E6F1C9FA563 for ; Mon, 27 Aug 2007 15:16:57 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 85245-01-9 for ; Mon, 27 Aug 2007 15:16:48 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from smaug.vex.net (smaug.vex.net [208.76.104.132]) by postgresql.org (Postfix) with ESMTP id 7508F9FB2CA for ; Mon, 27 Aug 2007 15:15:56 -0300 (ADT) Received: from dilbert (host-208-65-241-192.static.295.ca [208.65.241.192]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smaug.vex.net (Postfix) with ESMTP id 241E917947; Mon, 27 Aug 2007 14:15:55 -0400 (EDT) Date: Mon, 27 Aug 2007 14:15:52 -0400 From: "D'Arcy J.M. Cain" To: Joel Richard Cc: Claudia Kosny , sql pgsql Subject: Re: fetch first rows of grouped data Message-Id: <20070827141552.21ec3a54.darcy@druid.net> 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> X-Mailer: Sylpheed 2.4.3 (GTK+ 2.10.13; i386--netbsdelf) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/225 X-Sequence-Number: 29163 On Mon, 27 Aug 2007 13:34:09 -0400 Joel Richard 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 | 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.