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

Started by Tom Lanealmost 27 years ago2 messageshackers
Jump to latest
#1Tom Lane
tgl@sss.pgh.pa.us

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.

I'm using postgresql-snap-990329.tgz

Yeah, I see it too. This looks like a definite bug to me, but I have
other bugs to squash right now :-(. Anyone else want to jump on this?

regards, tom lane

#2Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#1)
Re: [HACKERS] Re: [SQL] Finding the "most recent" rows

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, Pennsylvania 19026