× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



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')
--

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.