Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace

Поиск
Список
Период
Сортировка
От Chris Bitmead
Тема Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace
Дата
Msg-id 388D13FE.4E75CA05@bitmead.com
обсуждение исходный текст
Ответ на DISTINCT ON: speak now or forever hold your peace  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace  (Peter Eisentraut <peter_e@gmx.net>)
Список pgsql-sql
Philip Warner wrote:
> >I don't feel overly strongly about this, but if I remember right you can
> >do some pretty cool things with this feature, provided you do define
> >some semantics clearly. Like I think you can find the first tuple
> >(given some ORDER BY clause) that fulfills some criteria. I think it is
> >
> >SELECT DISTINCT ON name name, age ORDER BY age;
> >
> >will get the youngest person. This might not be clearly specified now,
> >but
> >as long as it's useful, how about clearly defining it? I don't know that
> >there is an easy way of doing this in standard SQL.
> 
> I don't know about PGSQL, but in other systems, I use:
> 
>     Select <whatever> from <wherever> order by age asc limit to 1 row;
> 
> I *think* the PGSQL syntax is:
> 
>     Select <whatever> from <wherever> order by age asc limit 1;

I think what I really meant was...

SELECT DISTINCT ON firstname firstname, age ORDER BY age.

Which would find the youngest person called "fred", the youngest person
called "paul", the youngest person called "jim" etc etc. which your
limit example wouldn't do.


В списке pgsql-sql по дате отправления:

Предыдущее
От: Philip Warner
Дата:
Сообщение: Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace