Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 9CD531337B4E for ; Thu, 24 Feb 2011 16:22:03 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 76156-02 for ; Thu, 24 Feb 2011 20:21:57 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from proton.planetargon.com (proton.planetargon.com [198.145.115.11]) by mail.postgresql.org (Postfix) with ESMTP id 2FBFF1337B4A for ; Thu, 24 Feb 2011 16:21:55 -0400 (AST) Received: by proton.planetargon.com (Postfix, from userid 502) id 5E72082DDDC; Thu, 24 Feb 2011 12:21:55 -0800 (PST) Received: from [192.168.1.75] (unknown [68.64.144.221]) by proton.planetargon.com (Postfix) with ESMTP id 1257882DDD9; Thu, 24 Feb 2011 12:21:50 -0800 (PST) Subject: Re: Picking out the most recent row using a time stamp column Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: text/plain; charset=us-ascii From: Michael Glaesemann In-Reply-To: Date: Thu, 24 Feb 2011 15:21:49 -0500 Cc: pgsql-performance Content-Transfer-Encoding: 7bit Message-Id: <08B3368E-E623-4E9C-83F5-AB05B471AF4C@seespotcode.net> References: To: Dave Crooke X-Mailer: Apple Mail (2.1082) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201102/480 X-Sequence-Number: 42618 On Feb 24, 2011, at 14:55, Dave Crooke wrote: > Is there a more elegant way to write this, perhaps using PG-specific > extensions? SELECT DISTINCT ON (data.id_key) data.id_key, data.time_stamp, data.value FROM data ORDER BY data.id_key, data.time_stamp DESC; Michael Glaesemann grzm seespotcode net