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

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane)
Cc: chris(dot)bitmead(at)bigfoot(dot)com, pgsql-sql(at)postgreSQL(dot)org, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Re: [SQL] Finding the "most recent" rows
Date: 1999-04-23 19:43:11
Message-ID: 199904231943.PAA12098@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

> Chris Bitmead <chris(dot)bitmead(at)bigfoot(dot)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(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1999-04-23 19:53:03 Re: [HACKERS] Re: light dawns: serious bug in FE/BE protocol handling
Previous Message Bruce Momjian 1999-04-23 19:41:03 Re: [HACKERS] PostgreSQL Webpage -> PGSQL Advocacy

Browse pgsql-sql by date

  From Date Subject
Next Message Gregory Holston 1999-04-23 20:09:24 what is "cost"?
Previous Message Tom Lane 1999-04-23 16:29:28 Re: [SQL] Finding the "most recent" rows