Re: Best way to get the latest revision from a table - Mailing list pgsql-performance

From Shaun Thomas
Subject Re: Best way to get the latest revision from a table
Date
Msg-id 4D30D708.3020704@peak6.com
Whole thread Raw
In response to Best way to get the latest revision from a table  (Nikolas Everett <nik9000@gmail.com>)
Responses Re: Best way to get the latest revision from a table
List 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@peak6.com

______________________________________________

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

pgsql-performance by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: Best way to get the latest revision from a table
Next
From: "Kevin Grittner"
Date:
Subject: Re: Best way to get the latest revision from a table