From: Shane Ambler <pgsql@007Marketing.com>
To: Paefgen, Peter (LDS) <Peter.Paefgen@lds.nrw.de>
Cc: Chris Mulcahy <pgsql@cmulcahy.com>
Cc: pgsql-general@postgresql.org
Subject: Re: ORDER BY
Date: Wed, 22 Nov 2006 02:15:01 +1030
Message-ID: <45631EFD.8050106@007Marketing.com> (raw)
In-Reply-To: <AAC1FFFEE7335B439BE18A6EAB72174B01A29356@lds421.lds.nrw.de>
References: <AAC1FFFEE7335B439BE18A6EAB72174B01A29356@lds421.lds.nrw.de>
Paefgen, Peter (LDS) wrote:
> Hello,
>
> a) it is right, to place an ORDER BY at the end of the statement. That is the
> correct place to do this.
Correct - the ORDER BY at the end of the statement will apply to the
result set after the UNION has been done.
ORDER BY can be included in the sub-expression SELECT statements only if
they are enclosed in parenthesis and I believe it *must* also be
accompanied by a LIMIT clause.
> but
>
> b) UNION doesn't mean anyway an sort. UNION mean "eliminate dups". But there are
UNION means to join/combine together and if used on it's own will
eliminate duplicate rows in the result set.
Using UNION ALL will include any duplicates and run somewhat faster.
UNION itself does not imply any sort order but ORDER BY can be applied
to the result set of the UNION.
> several techniques to do that. One of them is "sort". So, if the development
> crew chooses to change the elimination algorithme, that would be, in sight of an
> UNION, ok .
As long as the columns returned match up to satisfy the UNION criteria
then changing the elimination algorithm will not break your use of UNION.
If they want to use ORDER BY x LIMIT 2 then that sub-select will need to
be surrounded by parenthesis.
> Best wishes,
> Regards,
> Peter
>
--
Shane Ambler
pgSQL@007Marketing.com
Get Sheeky @ http://Sheeky.Biz
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-general@postgresql.org
Cc: pgsql@007Marketing.com, Peter.Paefgen@lds.nrw.de, pgsql@cmulcahy.com
Subject: Re: ORDER BY
In-Reply-To: <45631EFD.8050106@007Marketing.com>
References: <AAC1FFFEE7335B439BE18A6EAB72174B01A29356@lds421.lds.nrw.de> <45631EFD.8050106@007Marketing.com>
* 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