I, and certainly many others, have used that same methodology to force a pseudo "order by".
As I recall, same circumstance - a UNION.
Roger Harman
COMMON Certified Application Developer - ILE RPG on IBM i on Power
-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Dave
Sent: Friday, October 6, 2023 5:49 AM
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxxxxxxxx>
Subject: RE: SQL results different after upgrading IBM i
Thanks, I knew I was going to get that reply and I know that the ORDER BY
clause should be added, but that wasn't what I was asking.
There is definitely a difference in behaviour and I think it must be
documented somewhere.
This case was particular for me : it was not possible to simply use order
by as this was not what was wanted; it was necessary for the result of the
first select statement to precede the second, so I added
Select '1', col1, col2, etc
union
Select '2', col1, col2, etc
order by 1
- *Subject*: RE: SQL results different after upgrading IBM i
- *From*: "Birgitta Hauser" <Hauser@xxxxxxxxxxxxxxx>
- *Date*: Fri, 6 Oct 2023 12:44:53 +0200
- *List-archive*: <
https://archive.midrange.com/midrange-l/>
- *List-post*: <mailto:midrange-l@xxxxxxxxxxxxxxxxxx
<midrange-l@xxxxxxxxxxxxxxxxxx>>
- *List-subscribe*: <
https://lists.midrange.com/mailman/listinfo/midrange-l>, <
mailto:midrange-l-request@xxxxxxxxxxxxxxxxxx?subject=subscribe
<midrange-l-request@xxxxxxxxxxxxxxxxxx?subject=subscribe>>
- *List-unsubscribe*: <
https://lists.midrange.com/mailman/options/midrange-l>, <
mailto:midrange-l-request@xxxxxxxxxxxxxxxxxx?subject=unsubscribe
<midrange-l-request@xxxxxxxxxxxxxxxxxx?subject=unsubscribe>>
------------------------------
The old rule: If you need the records in a specific sequence, you have to
add an ORDER BY.
It is the Query Optimizer if and which access path is used, and the
decision depends on among others on the data composition.
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
Modernization - Education - Consulting on IBM i
IBM Champion since 2020
"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
"Train people well enough so they can leave, treat them well enough so they
don't want to. " (Richard Branson)
"Learning is experience ... everything else is only information!" (Albert
Einstein)
-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Dave
Sent: Friday, 6 October 2023 10:11
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxxxxxxxx>
Subject: Fwd: SQL results different after upgrading IBM i
Hello all,
Since changing the i and upgrading from V7.1 to V7.3, it has been
discovered that at at least 2 SQL statements are no longer working in the
same way.
Could it be that there was some kind of system parameter concerning the
usage of SQL that was missed ?
In the example below, no order by clause was added as it was assumed that
the lines resulting from the part of the statement preceding « UNION »
would appear in the final table before those in the latter part of the
statement.
Ie, line B followed by line L.
If the statement is issued in an interactive sql session then this is the
case. However, the statement is being used in a cursor in a sqlrpgle
program, and since changing the i, the result is line L followed by line B.
Thanks in advance for any input.
Data in physical file
Type Code
B ****
L ****
SELECT distinct type, Code FROM MyTable
WHERE 1=1
AND type = 'B'
UNION
SELECT distinct type, Code FROM MyTable
WHERE 1=1
AND type IN ( 'L', 'M')
--
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
https://archive.midrange.com/midrange-l.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.
As an Amazon Associate we earn from qualifying purchases.