Re: SQL Newbie - Mailing list pgsql-sql

From Owen Jacobson
Subject Re: SQL Newbie
Date
Msg-id 001601c59f68$6b2fff50$9b00015a@osl.com
Whole thread Raw
In response to Re: SQL Newbie  ("Nick Stone" <nick@harelane.com>)
List 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



pgsql-sql by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: SQL Newbie
Next
From: Bruno Wolff III
Date:
Subject: Re: SQL Newbie