From: Owen Jacobson <ojacobson@osl.com>
To: pgsql-sql@postgresql.org
Subject: Re: SQL Newbie
Date: Fri, 12 Aug 2005 11:05:26 -0700
Message-ID: <001601c59f68$6b2fff50$9b00015a@osl.com> (raw)
In-Reply-To: <20050812175529.82D7F24F3B9@smtp.nildram.co.uk>
Nick Stone wrote:
> Hope this helps
>
> SELECT
> *
> FROM
> speed_history as outside etc..
> WHERE
> (speed = (
> SELECT
> speed
> FROM
> speed_history as inside etc..
> WHERE
> (outside.interface = inside.interface)
> LIMIT 1
> ORDER BY
> speed DESC
> )
> )
Worth noting that ORDER BY speed DESC LIMIT 1 is fundamentally the same as
MAX (speed), except that MAX (speed) doesn't take advantage of any index
present. This is a fairly common idiom but a self-described SQL Newbie may
not see the equivalence instantly.
-Owen
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: ojacobson@osl.com
Subject: Re: SQL Newbie
In-Reply-To: <001601c59f68$6b2fff50$9b00015a@osl.com>
* 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