| From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
|---|---|
| To: | Nick Stone <nick(at)harelane(dot)com> |
| Cc: | 'Lane Van Ingen' <lvaningen(at)esncc(dot)com>, pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: SQL Newbie |
| Date: | 2005-08-12 19:39:23 |
| Message-ID: | 20050812193923.GA10364@wolff.to |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On Fri, Aug 12, 2005 at 18:57:34 +0100,
Nick Stone <nick(at)harelane(dot)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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bruno Wolff III | 2005-08-13 00:04:54 | Re: Fwd: How to encrypt a column |
| Previous Message | Owen Jacobson | 2005-08-12 18:05:26 | Re: SQL Newbie |