Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 71E929FA075 for ; Tue, 28 Aug 2007 10:00:50 -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 45256-03 for ; Tue, 28 Aug 2007 10:00:45 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mtao04.charter.net (mtao04.charter.net [209.225.8.178]) by postgresql.org (Postfix) with ESMTP id 7F7F89F95EB for ; Tue, 28 Aug 2007 10:00:45 -0300 (ADT) Received: from aa02.charter.net ([10.20.200.154]) by mtao04.charter.net (InterMail vM.7.08.02.00 201-2186-121-20061213) with ESMTP id <20070828130043.BMKE23660.mtao04.charter.net@aa02.charter.net>; Tue, 28 Aug 2007 09:00:43 -0400 Received: from [10.0.1.3] (really [66.188.165.91]) by aa02.charter.net with ESMTP id <20070828130043.MZQB26124.aa02.charter.net@[10.0.1.3]>; Tue, 28 Aug 2007 09:00:43 -0400 In-Reply-To: <20070828091421.GB19637@depesz.com> References: <46D2FD9F.3020000@gmx.net> <20070828091421.GB19637@depesz.com> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <2A02E93C-62E7-4D94-8559-B0999835698F@seespotcode.net> Cc: Claudia Kosny , pgsql-sql@postgresql.org Content-Transfer-Encoding: 7bit From: Michael Glaesemann Subject: Re: fetch first rows of grouped data Date: Tue, 28 Aug 2007 08:00:42 -0500 To: depesz@depesz.com X-Mailer: Apple Mail (2.752.2) X-Chzlrs: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/235 X-Sequence-Number: 29173 On Aug 28, 2007, at 4:14 , hubert depesz lubaczewski wrote: > On Mon, Aug 27, 2007 at 06:36:47PM +0200, Claudia Kosny wrote: >> Is there a way to do this with one query? >> I am using PostgreSQL 7.4. > > you can try to use "distinct on". I considered that as well, but couldn't think of a way to return more than one row per "distinct on condition". I'd be interested to hear if you've thought of a way to use DISTINCT ON in this situation. Michael Glaesemann grzm seespotcode net