pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philip Warner <pjw@rhyme.com.au>
To: josh@agliodbs.com, sqllist <pgsql-sql@postgresql.org>
Subject: Re: [Fwd: Re: no ORDER BY in subselects?]
Date: Thu, 21 Sep 2000 11:29:54 +1000
Message-ID: <3.0.5.32.20000921112954.00c9be00@mail.rhyme.com.au> (raw)
In-Reply-To: <39C8E3C9.D1CFFDB3@agliodbs.com>

At 09:20 20/09/00 -0700, Josh Berkus wrote:
>Ooops, posted this to Phillip rather than the list, sorry Phillip ...
>
>Folks,
>
>Philip Warner wrote:
>> 
>> At 15:23 20/09/00 +0200, Louis-David Mitterrand wrote:
>> >
>> >ERROR:  parser: parse error at or near "order"
>> >
>> >Aren't ORDER BY clauses allowed in subselects?
>> >
>> 
>> It is a very very sad fact, but, no, they're not.
>
>Hmmmm ... can't say as I've ever seen an ORDER BY in a subselect before.
>Why would you want one?
>

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 ...

OR

  select <whatever>, (select Start_Date from table where Start_Date >
this.Start_Date
  Order By Start_Date asc limit 1) as End_Date


>And if you do want one, Louis-David, you can always use a temporary
>table as previously described.

It is A LOT less clean.

The fact that Dec RDB, Oracle and SQL/Server all allow it probably means
that there is a reasonable user base out there who think it's a good idea.


----------------------------------------------------------------
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   |/



view thread (6+ messages)  latest in thread

Message-ID: <3.0.5.32.20000921112954.00c9be00@mail.rhyme.com.au>
Permalink:  ../3.0.5.32.20000921112954.00c9be00@mail.rhyme.com.au/
Also on:    postgresql.org/message-id/3.0.5.32.20000921112954.00c9be00@mail.rhyme.com.au

 · 

reply

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
  Subject: Re: [Fwd: Re: no ORDER BY in subselects?]
  In-Reply-To: <3.0.5.32.20000921112954.00c9be00@mail.rhyme.com.au>
  References: <39C8E3C9.D1CFFDB3@agliodbs.com> <3.0.5.32.20000921112954.00c9be00@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