Re: Grabbing Newest Records From Duplicates

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Travis Whitton" <tinymountain(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Grabbing Newest Records From Duplicates
Date: 2007-03-16 15:35:40
Message-ID: 7240.1174059340@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Travis Whitton" <tinymountain(at)gmail(dot)com> 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gerardo Herzig 2007-03-16 15:50:32 log file permissions?
Previous Message Travis Whitton 2007-03-16 15:28:48 Grabbing Newest Records From Duplicates