Обсуждение: Re: [HACKERS] Re: [SQL] Finding the "most recent" rows

Поиск
Список
Период
Сортировка

Re: [HACKERS] Re: [SQL] Finding the "most recent" rows

От
Bruce Momjian
Дата:
> Chris Bitmead <chris.bitmead@bigfoot.com> writes:
> >>>>>>> select title, summary, time from story t where time = (select
> >>>>>>> max(s.time) from story s GROUP BY s.title);
> >> 
> >>>> Why doesn't replacing "=" with "IN" produce a result? It wouldn't be the
> >>>> desired result, but I thought this was legal.
> >> 
> >> I thought so too (on both counts).  Are you saying it doesn't work?
> >> What happens?  Which version are you using?
> 
> > httpd=> select title, summary, time from story t where time IN (select
> > max(s.time) from story s GROUP BY s.title);
> > ERROR:  parser: Subselect has too many or too few fields.

This is not legal.  If you use GROUP BY, the field must be in the target
list.  In this case, s.title is not in the target list of the subselect.
I realize it can't be in the subselect target list because you can only
have one column in the target list, but that is the case.

--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026