Re: SQL Newbie

From: "Owen Jacobson" <ojacobson(at)osl(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: SQL Newbie
Date: 2005-08-12 18:05:26
Message-ID: 001601c59f68$6b2fff50$9b00015a@osl.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2005-08-12 19:39:23 Re: SQL Newbie
Previous Message Bruno Wolff III 2005-08-12 18:04:55 Re: SQL Newbie