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.