From: Philip Warner <pjw@rhyme.com.au>
To: Frank Bax <fbax@execulink.com>
To: pgsql-sql@postgresql.org
Subject: Re: [Fwd: Re: no ORDER BY in subselects?]
Date: Fri, 22 Sep 2000 04:35:17 +1000
Message-ID: <3.0.5.32.20000922043517.02f093d0@mail.rhyme.com.au> (raw)
In-Reply-To: <3.0.6.32.20000921115010.0097e1b0@execulink.com>
References: <3.0.5.32.20000921112954.00c9be00@mail.rhyme.com.au>
<39C8E3C9.D1CFFDB3@agliodbs.com>
At 11:50 21/09/00 -0400, Frank Bax wrote:
>At 11:29 AM 9/21/00 +1000, you wrote:
>>The main reason I use them is to find the 'next' or 'previous' record in a
>>list (eg. next date, next ID). eg.
>>
>> select <whatever>, (select ID from table where id > this.id
>> order by id asc limit 1) as next_id ...
>
>Doesn't this give the same result (without order by):
>
>> select <whatever>, (select min(ID) from table where id > this.id) as
>next_id
Yes, but I don't think PostgreSQL is smart enough to use indexes to
evaluate the Min() function.
Also, min/max does not work quite so well with a slightly more complex
example:
select <whatever>, (select ID from table where date_field > this.date_field
order by date_field asc limit 1) as next_id ...
(ie. if the date_field and id are not correlated, but you want the id
corresponding to the next date).
----------------------------------------------------------------
Philip Warner | __---_____
Albatross Consulting Pty. Ltd. |----/ - \
(A.B.N. 75 008 659 498) | /(@) ______---_
Tel: (+61) 0500 83 82 81 | _________ \
Fax: (+61) 0500 83 82 82 | ___________ |
Http://www.rhyme.com.au | / \|
| --________--
PGP key available upon request, | /
and from pgp5.ai.mit.edu:11371 |/
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: pjw@rhyme.com.au, fbax@execulink.com
Subject: Re: [Fwd: Re: no ORDER BY in subselects?]
In-Reply-To: <3.0.5.32.20000922043517.02f093d0@mail.rhyme.com.au>
References: <3.0.5.32.20000921112954.00c9be00@mail.rhyme.com.au> <39C8E3C9.D1CFFDB3@agliodbs.com> <3.0.5.32.20000922043517.02f093d0@mail.rhyme.com.au>
* 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