From: Tom Lane <tgl@sss.pgh.pa.us>
To: Travis Whitton <tinymountain@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Grabbing Newest Records From Duplicates
Date: Fri, 16 Mar 2007 11:35:40 -0400
Message-ID: <7240.1174059340@sss.pgh.pa.us> (raw)
In-Reply-To: <cf9b4f3e0703160828s2cc0b9v6c01db6e8634e37e@mail.gmail.com>
References: <cf9b4f3e0703160828s2cc0b9v6c01db6e8634e37e@mail.gmail.com>
"Travis Whitton" <tinymountain@gmail.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, tinymountain@gmail.com
Subject: Re: Grabbing Newest Records From Duplicates
In-Reply-To: <7240.1174059340@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox