Re: Best way to get the latest revision from a table

From: Shaun Thomas <sthomas(at)peak6(dot)com>
To: Nikolas Everett <nik9000(at)gmail(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Best way to get the latest revision from a table
Date: 2011-01-14 23:06:48
Message-ID: 4D30D708.3020704@peak6.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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(at)peak6(dot)com

______________________________________________

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

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Kevin Grittner 2011-01-14 23:33:27 Re: Best way to get the latest revision from a table
Previous Message Kevin Grittner 2011-01-14 22:57:11 Re: Best way to get the latest revision from a table