Re: [HACKERS] Re: [SQL] Finding the "most recent" rows - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: [HACKERS] Re: [SQL] Finding the "most recent" rows
Date
Msg-id 199904231943.PAA12098@candle.pha.pa.us
Whole thread Raw
List pgsql-hackers
> 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
 


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] PostgreSQL Webpage -> PGSQL Advocacy
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] Re: light dawns: serious bug in FE/BE protocol handling