Re: [SQL] Finding the "most recent" rows

From: Julian Scarfe <jas1(at)scigen(dot)co(dot)uk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: [SQL] Finding the "most recent" rows
Date: 1999-04-23 10:30:14
Message-ID: 37204BB5.B6CD57B9@scigen.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message José Soares 1999-04-23 14:25:47 Re: [SQL] SELECT TOP X -- part 2 -- parse error?
Previous Message Chairudin Sentosa 1999-04-23 09:13:12 Re: [INTERFACES] where did that date and time come from??