From: Tom Lane <tgl@sss.pgh.pa.us>
To: Chris Bitmead <chris.bitmead@bigfoot.com>
Cc: pgsql-sql@postgresql.org <pgsql-sql@postgreSQL.org>
Subject: Re: [SQL] Finding the "most recent" rows
Date: Thu, 22 Apr 1999 20:45:06 -0400
Message-ID: <20211.924828306@sss.pgh.pa.us> (raw)
In-Reply-To: <371FB76C.65A146D7@bigfoot.com>
Chris Bitmead <chris.bitmead@bigfoot.com> writes:
> Clever. But why doesn't this work....
> select title, summary, time from story t where time = (select
> max(s.time) from story s GROUP BY s.title);
> ERROR: parser: Subselect has too many or too few fields.
A subselect used in an expression has to return exactly one value;
yours will return as many tuples as there are distinct titles.
I think you meant
select title, summary, time from story t where time = (select
max(s.time) from story s WHERE s.title = t.title);
Here the subselect should give a single result each time it's
executed. Unfortunately, it's gonna be executed once for each
tuple scanned by the outer select :-(
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, chris.bitmead@bigfoot.com
Subject: Re: [SQL] Finding the "most recent" rows
In-Reply-To: <20211.924828306@sss.pgh.pa.us>
References: <371FB76C.65A146D7@bigfoot.com> <20211.924828306@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox