Re: problem query ...

От
John Taylor
Тема
Re: problem query ...
Дата
Msg-id
02013117082906.01674@splash.hq.jtresponse.co.uk
Ответ на
Список
Дерево обсуждения
problem query ... John Taylor <postgres@jtresponse.co.uk>
Re: problem query ... Ugly Hippo <ugly_hippo@yahoo.ca>
Re: problem query ... Frank Bax <fbax@sympatico.ca>
Re: problem query ... John Taylor <postgres@jtresponse.co.uk>
Re: problem query ... Tom Lane <tgl@sss.pgh.pa.us>
Re: problem query ... Tom Lane <tgl@sss.pgh.pa.us>
Re: problem query ... John Taylor <postgres@jtresponse.co.uk>
On Thursday 31 January 2002 17:02, Tom Lane wrote:
> John Taylor  writes:
> > I want to return 1 row for each id, that contains the maximum update
> > value for that id, and the values for name and desc.
> 
> There's no simple way to do that in standard SQL.  However you can do
> it easily with SELECT DISTINCT ON, if you don't mind using a nonstandard
> construct.  See the "weather report" example on the SELECT reference
> page.

That was it!
I did try distinct on before, but was trying to be too complicated, with group or subselects.
What I wanted is:

select distinct on (id)  id,name,descr from john order by id,update desc; 

Thanks
JohnT
В списке pgsql-novice по дате отправления
От: Chris Thompson
Дата:
От: Frank Bax
Дата:
Сообщение: Re: problem query ...
Поиск
Список
Период
Сортировка
Искать
FAQ