From: Bruno Wolff III <bruno@wolff.to>
To: Nick Stone <nick@harelane.com>
Cc: Lane Van Ingen <lvaningen@esncc.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL Newbie
Date: Fri, 12 Aug 2005 14:39:23 -0500
Message-ID: <20050812193923.GA10364@wolff.to> (raw)
In-Reply-To: <20050812175529.82D7F24F3B9@smtp.nildram.co.uk>
References: <EKEMKEFLOMKDDLIALABIKEEECBAA.lvaningen@esncc.com>
<20050812175529.82D7F24F3B9@smtp.nildram.co.uk>
On Fri, Aug 12, 2005 at 18:57:34 +0100,
Nick Stone <nick@harelane.com> 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
> )
> )
>
> Hopefully you get the idea - basically it's a corelated sub-query - very
> useful
>
Note that you want to order by interface DESC, speed DESC in the subselect
and have an index on (interface, speed) for this to really be efficient.
I think 8.1 might be smart enough to use an index on (interface, speed)
in the above case, but currently released versions won't.
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: bruno@wolff.to, nick@harelane.com, lvaningen@esncc.com
Subject: Re: SQL Newbie
In-Reply-To: <20050812193923.GA10364@wolff.to>
* 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