Yep. ORDER BY applies to the entire output data set (i.e. both SELECTs).
You could add an additional field to your SELECTs and ORDER BY to act as a
group number. That would insure that everything in SELECT #1 would show up
before SELECT #2, but within each group they would all be sorted the same.
Richard
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Stone, Joel
Sent: Thursday, February 13, 2014 5:25 PM
To: midrange-l@xxxxxxxxxxxx
Subject: SQL UNION and ORDER BY
I would like to have a
SELECT with an ORDER BY
And UNION this to another SELECT without an order by.
Is this possible?
It seems that SQL requires the ORDER BY to sort the entire result file.
Thanks
select fieldnames
FROM fileA
ORDER BY field1, field2
UNION all
SELECT
More field names
FROM from
______________________________________________________________________
This outbound email has been scanned for all viruses by the MessageLabs
Skyscan service.
For more information please visit
http://www.symanteccloud.com
______________________________________________________________________
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe,
or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at
http://archive.midrange.com/midrange-l.
****************************************************************************
********
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer
viruses.
****************************************************************************
********
-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2014.0.4335 / Virus Database: 3697/7089 - Release Date: 02/13/14
-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2014.0.4335 / Virus Database: 3697/7089 - Release Date: 02/13/14
As an Amazon Associate we earn from qualifying purchases.