pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Shaun Thomas <sthomas@peak6.com>
To: Nikolas Everett <nik9000@gmail.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Best way to get the latest revision from a table
Date: Fri, 14 Jan 2011 17:06:48 -0600
Message-ID: <4D30D708.3020704@peak6.com> (raw)
In-Reply-To: <AANLkTikVZG_Us9R9iLdz=GnqqEnHE5D7Go9xkENkdGiQ@mail.gmail.com>
References: <AANLkTikVZG_Us9R9iLdz=GnqqEnHE5D7Go9xkENkdGiQ@mail.gmail.com>

On 01/14/2011 03:17 PM, Nikolas Everett wrote:

> SELECT *
>    FROM request
>    JOIN (SELECT a, MAX(b) as b FROM test GROUP BY a) max USING (a)
>    JOIN test USING (a, b);

This actually looks like a perfect candidate for DISTINCT ON.

SELECT DISTINCT ON (a, b) a, b, revision
   FROM test
  ORDER BY a, b DESC;

Maybe I'm just misunderstanding your situation, though.

-- 
Shaun Thomas
OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604
312-676-8870
sthomas@peak6.com

______________________________________________

See  http://www.peak6.com/email_disclaimer.php
for terms and conditions related to this email



view thread (13+ messages)  latest in thread

Message-ID: <4D30D708.3020704@peak6.com>
Permalink:  ../4D30D708.3020704@peak6.com/
Also on:    postgresql.org/message-id/4D30D708.3020704@peak6.com

 · 

reply

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-performance@postgresql.org
  Cc: sthomas@peak6.com, nik9000@gmail.com
  Subject: Re: Best way to get the latest revision from a table
  In-Reply-To: <4D30D708.3020704@peak6.com>

* 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