Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id C8C879F987D for ; Mon, 27 Aug 2007 13:51:12 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 83250-05 for ; Mon, 27 Aug 2007 13:51:08 -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 2A63E9F9586 for ; Mon, 27 Aug 2007 13:51:08 -0300 (ADT) Received: from dilbert (dilbert.druid.net [207.35.13.112]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smaug.vex.net (Postfix) with ESMTP id B819717960; Mon, 27 Aug 2007 12:51:04 -0400 (EDT) Date: Mon, 27 Aug 2007 12:51:02 -0400 From: "D'Arcy J.M. Cain" To: Claudia Kosny Cc: pgsql-sql@postgresql.org Subject: Re: fetch first rows of grouped data Message-Id: <20070827125102.e52b43de.darcy@druid.net> In-Reply-To: <46D2FD9F.3020000@gmx.net> References: <46D2FD9F.3020000@gmx.net> 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-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200708/222 X-Sequence-Number: 29160 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.