Re: [SQL] Most recent row

Поиск
Список
Период
Сортировка
Искать
От
Gary Stainburn
Тема
Re: [SQL] Most recent row
Дата
в 12:13:07
Msg-id
201705051013.07196.gary.stainburn@ringways.co.uk
Ответ на
Re: [SQL] Most recent row (Karsten Hilbert)
Список
Дерево обсуждения
[SQL] Most recent row Gary Stainburn <gary.stainburn@ringways.co.uk>
Re: [SQL] Most recent row Karsten Hilbert <Karsten.Hilbert@gmx.net>
Re: [SQL] Most recent row Gary Stainburn <gary.stainburn@ringways.co.uk>
Re: [SQL] Most recent row hubert depesz lubaczewski <depesz@depesz.com>
Re: [SQL] Most recent row Gary Stainburn <gary.stainburn@ringways.co.uk>
Re: [SQL] Most recent row hubert depesz lubaczewski <depesz@depesz.com>
Re: [SQL] Most recent row Gary Stainburn <gary.stainburn@ringways.co.uk>
Re: [SQL] Most recent row hubert depesz lubaczewski <depesz@depesz.com>
Re: [SQL] Most recent row Gary Stainburn <gary.stainburn@ringways.co.uk>
Re: [SQL] Most recent row Bob Edwards <bob@cs.anu.edu.au>
Re: [SQL] Most recent row vinny <vinny@xs4all.nl>
Re: [SQL] Most recent row "David G. Johnston" <david.g.johnston@gmail.com>
Re: [SQL] Most recent row Adrian Klaver <adrian.klaver@aklaver.com>
Re: [SQL] Most recent row Michael Moore <michaeljmoore@gmail.com>
Re: [SQL] Most recent row Michael Moore <michaeljmoore@gmail.com>
Re: [SQL] Most recent row Michael Moore <michaeljmoore@gmail.com>
Re: [SQL] Most recent row Thomas Kellerer <spam_eater@gmx.net>
On Friday 05 May 2017 09:32:21 Karsten Hilbert wrote:
> On Fri, May 05, 2017 at 09:25:04AM +0100, 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
> >   ..
> > ;
>
> You will need to provide a definition for *exactly* what
> "most recent" means in this context.
>
> Karsten

Appologies all.  I though that was obvious, but it is only obvious for me.

What I mean by most recent is the assessment record with the highest (most 
recent) timestamp. Specfically join a people row with the  assessment row for 
that people.

Each assessment will assign scores for the person being assessed.  The scores 
from their most recent assessment are their current scores and what I want to 
appear in the view.  In the live project it will actually be a left outer 
join in case the person has not yet been assessed.


В списке pgsql-sql по дате отправления
От: vinny
Дата:
Сообщение: Re: [SQL] Most recent row
От: hubert depesz lubaczewski
Дата:
Сообщение: Re: [SQL] Most recent row
FAQ