X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 648AB8B9E6D for ; Tue, 8 Feb 2005 01:16:40 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 27820-04 for ; Tue, 8 Feb 2005 01:16:27 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id C58C38B9D5F for ; Tue, 8 Feb 2005 01:16:29 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id j181GRT7017352 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 7 Feb 2005 18:16:29 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id j181GQoj044055; Mon, 7 Feb 2005 18:16:26 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id j181GQGh044054; Mon, 7 Feb 2005 18:16:26 -0700 (MST) (envelope-from mfuhr) Date: Mon, 7 Feb 2005 18:16:26 -0700 From: Michael Fuhr To: q2005 Cc: pgsql-sql@postgresql.org Subject: Re: the best way to get the first record from each group Message-ID: <20050208011626.GA43996@winnie.fuhr.org> References: <005201c50d76$33dbec00$1400a8c0@jac> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <005201c50d76$33dbec00$1400a8c0@jac> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.002 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200502/103 X-Sequence-Number: 20214 On Tue, Feb 08, 2005 at 10:36:17AM +1000, q2005 wrote: > > Is there any better alternative to get the first record from each group? PostgreSQL has a non-standard SELECT DISTINCT ON query for just this purpose. http://www.postgresql.org/docs/8.0/static/queries-select-lists.html#QUERIES-DISTINCT http://www.postgresql.org/docs/8.0/static/sql-select.html#SQL-DISTINCT -- Michael Fuhr http://www.fuhr.org/~mfuhr/