Re: [SQL] Finding the "most recent" rows - Mailing list pgsql-sql

From Julian Scarfe
Subject Re: [SQL] Finding the "most recent" rows
Date
Msg-id 37204BB5.B6CD57B9@scigen.co.uk
Whole thread Raw
In response to Re: [SQL] Finding the "most recent" rows  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [SQL] Finding the "most recent" rows
List pgsql-sql
Tom Lane wrote:
> 
> SELECT DISTINCT ON place * FROM table ORDER BY place, time DESC;
> 
> might do the right thing.  It *seems* to select the first row for each
> value of place.  I've never seen a spec for this feature, however, so
> I'm not sure if it's reliable or not...

Works a treat when I try it on the "real" database (using 6.4.2). It seems
very efficient. I didn't realise that "DISTINCT ON" worked that way with an
"ORDER BY".

I must say I'm overwhelmed by the variety of constructive responses to my
request.  Thank you all very much.  It beats the hell out of sitting as no 17
in a premium rate telephone queue for support from a vendor of a "commercial"
product.
-- 

Julian Scarfe


pgsql-sql by date:

Previous
From: Chris Bitmead
Date:
Subject: Re: [SQL] Finding the "most recent" rows
Next
From: José Soares
Date:
Subject: Re: [SQL] SELECT TOP X -- part 2 -- parse error?