Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id B18FC9F96F0 for ; Mon, 27 Aug 2007 14:55:26 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 98555-03 for ; Mon, 27 Aug 2007 14:55:20 -0300 (ADT) X-Greylist: delayed 00:21:36.086132 by SQLgrey-1.7.5 Received: from mail.richard-group.com (db1.richard-group.com [66.231.181.240]) by postgresql.org (Postfix) with ESMTP id 5ACA39F926B for ; Mon, 27 Aug 2007 14:55:22 -0300 (ADT) Received: from [192.168.1.103] (wsip-70-167-243-23.dc.dc.cox.net [70.167.243.23]) by mail.richard-group.com (Postfix) with ESMTP id 9901FE9479; Mon, 27 Aug 2007 13:33:42 -0400 (EDT) In-Reply-To: <20070827125102.e52b43de.darcy@druid.net> References: <46D2FD9F.3020000@gmx.net> <20070827125102.e52b43de.darcy@druid.net> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <4CB5D209-C0CC-466E-A967-E766D6AD799B@joelrichard.com> Cc: sql pgsql Content-Transfer-Encoding: 7bit From: Joel Richard Subject: Re: fetch first rows of grouped data Date: Mon, 27 Aug 2007 13:34:09 -0400 To: "D'Arcy J.M. Cain" , Claudia Kosny X-Mailer: Apple Mail (2.752.2) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200708/223 X-Sequence-Number: 29161 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. So far, I haven't come up with any clever ideas. I'm not sure this can be done in SQL. --Joel On Aug 27, 2007, at 12:51 PM, D'Arcy J.M. Cain wrote: > On Mon, 27 Aug 2007 18:36:47 +0200 > Claudia Kosny wrote: >> I have a list of events that take place in a certain city at a >> certain >> date. Now I would like to have the first two (ordered by date) events >> for each city. >> >> Is there a way to do this with one query? >> I am using PostgreSQL 7.4. > > I believe you are looking for the LIMIT keyword. Check the docs on > the > web site. > > -- > 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. > > ---------------------------(end of > broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster