Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 2E6569FBF89 for ; Fri, 16 Mar 2007 12:35:52 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 28697-02 for ; Fri, 16 Mar 2007 12:35:43 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id C064B9FBEEE for ; Fri, 16 Mar 2007 12:35:43 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l2GFZeml007241; Fri, 16 Mar 2007 11:35:40 -0400 (EDT) To: "Travis Whitton" cc: pgsql-sql@postgresql.org Subject: Re: Grabbing Newest Records From Duplicates In-reply-to: References: Comments: In-reply-to "Travis Whitton" message dated "Fri, 16 Mar 2007 10:28:48 -0500" Date: Fri, 16 Mar 2007 11:35:40 -0400 Message-ID: <7240.1174059340@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/229 X-Sequence-Number: 27867 "Travis Whitton" writes: > Given the following test table, I want to grab only the newest record and > disregard any older duplicates based on name. Is this the most efficient way > to do it? No, it's gonna be pretty awful. The best way I know of involves DISTINCT ON (see the "weather reports" example in the SELECT reference page). Unfortunately that's a Postgres-only construct. If you want something portable then you'll need something messy with subqueries... regards, tom lane