agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: vinny <vinny@xs4all.nl>
To: Gary Stainburn <gary.stainburn@ringways.co.uk>
Cc: pgsql-sql@postgresql.org
Cc: pgsql-sql-owner@postgresql.org
Subject: Re: Most recent row
Date: Fri, 05 May 2017 10:50:36 +0200
Message-ID: <7690a8d6f9fd1ce96b89f97425d8ae33@xs4all.nl> (raw)
In-Reply-To: <201705050925.04194.gary.stainburn@ringways.co.uk>
References: <201705050925.04194.gary.stainburn@ringways.co.uk>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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?


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (17+ messages)  latest in thread

Message-ID: <7690a8d6f9fd1ce96b89f97425d8ae33@xs4all.nl>
Permalink:  ../7690a8d6f9fd1ce96b89f97425d8ae33@xs4all.nl/
Also on:    postgresql.org/message-id/7690a8d6f9fd1ce96b89f97425d8ae33@xs4all.nl

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: vinny@xs4all.nl, gary.stainburn@ringways.co.uk, pgsql-sql-owner@postgresql.org
  Subject: Re: Most recent row
  In-Reply-To: <7690a8d6f9fd1ce96b89f97425d8ae33@xs4all.nl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox