Re: [SQL] Most recent row - Mailing list pgsql-sql

From vinny
Subject Re: [SQL] Most recent row
Date
Msg-id 7690a8d6f9fd1ce96b89f97425d8ae33@xs4all.nl
Whole thread Raw
In response to [SQL] Most recent row  (Gary Stainburn <gary.stainburn@ringways.co.uk>)
List pgsql-sql
On 2017-05-05 10:25, Gary Stainburn wrote:
> This question has been asked a few times, and Google returns a few 
> different
> answers, but I am interested people's opinions and suggestions for the 
> *best*
> wat to retrieve the most recent row from a table.
> 
> My case is:
> 
> create table people (
>   p_id  serial primary key,
>  ......
> );
> 
> create table assessments (
>   p_id    int4 not null references people(p_id),
>   as_timestamp    timestamp not null,
>   ......
> );
> 
> select p.*, (most recent) a.*
>   from people p, assessments a
>   ..
> ;

It depends on what you mean by 'most recent'. Do you mean "the row I 
just inserted" or "the row with a date closest to now()" or perhaps some 
other definition?



pgsql-sql by date:

Previous
From: Karsten Hilbert
Date:
Subject: Re: [SQL] Most recent row
Next
From: Gary Stainburn
Date:
Subject: Re: [SQL] Most recent row