Re: SQL: UNION ALL and ORDER BY
From: Philip Lijnzaad <lijnzaad_at_ebi.ac.uk>
Date: 11 Jul 2001 16:31:06 +0100
Message-ID: <u74rsjscsl.fsf_at_sol6.ebi.ac.uk>
Date: 11 Jul 2001 16:31:06 +0100
Message-ID: <u74rsjscsl.fsf_at_sol6.ebi.ac.uk>
> I have an SQL QUERY containing a number of SELECT FROM WHERE's joined
> by UNION ALL statements. Following the last statement is a single
> ORDER BY clause.
> On my system the ORDER BY affects the order of all the results from
> the preceding SELECTs.
Of course; ORDER BY operates on the preceding complete set, and I think in fact you can only legally have only one ORDER BY statement, which has to be at the end of the query (and some would claim it's not even part of the query, because sets are by definition not ordered).
> As I may wish to port this to other databases, is the feature
> described above standard SQL or specific to my implementation?
yes, I think so.
Philip
-- If you have a procedure with 10 parameters, you probably missed some. (Kraulis) ----------------------------------------------------------------------------- Philip Lijnzaad, lijnzaad_at_ebi.ac.uk \ European Bioinformatics Institute,rm A2-08 +44 (0)1223 49 4639 / Wellcome Trust Genome Campus, Hinxton +44 (0)1223 49 4468 (fax) \ Cambridgeshire CB10 1SD, GREAT BRITAINReceived on Wed Jul 11 2001 - 17:31:06 CEST