MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Order by clause in DB2

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
pkrish_18
Beginner


Joined: 08 Apr 2005
Posts: 12
Topics: 7

PostPosted: Tue Mar 07, 2006 7:54 am    Post subject: Order by clause in DB2 Reply with quote

I'm running the following query..

SELECT *
FROM RBPRDB.T1508
WHERE SO_CD = 'EO1148HJ'
AND SI_NUM = 01
AND SD_NUM = 02
AND SSI_CD = 'A01'
ORDER BY MOT_MFG_DUNS_CD ASC
WITH UR;

I have the Primary key and Unique Index defined on the following columns

SO_CD
SI_NUM
SD_NUM
SSI_CD
KANBAN_CD

column MOT_MFG_DUNS_CD is a notnull column but has spaces.

1) The resultant of the above query (with order by clause) is

SO_CD SI_NUM SD_NUM SSI_CD KANBAN_CD
---------+---------+---------+---------+---------+---------+---------+---
EO1148HJ 1 2 A01 ECF22T05
EO1148HJ 1 2 A01 ECF22T04
EO1148HJ 1 2 A01 ECF22T01
EO1148HJ 1 2 A01 ECF22T03
EO1148HJ 1 2 A01 ECF22T02
DSNE610I NUMBER OF ROWS DISPLAYED IS 5


2) The resultant of the above query (without order by clause) is

SO_CD SI_NUM SD_NUM SSI_CD KANBAN_CD
---------+---------+---------+---------+---------+------
EO1148HJ 1 2 A01 ECF22T01
EO1148HJ 1 2 A01 ECF22T02
EO1148HJ 1 2 A01 ECF22T03
EO1148HJ 1 2 A01 ECF22T04
EO1148HJ 1 2 A01 ECF22T05

Note that MOT_MFG_DUNS_CD has spaces for all the 5 retrieved row.

Would like to know why there is a difference in the display order of the Kanban_CD .
Back to top
View user's profile Send private message
Manas Biswal
Intermediate


Joined: 29 Nov 2002
Posts: 382
Topics: 27
Location: Chennai, India

PostPosted: Tue Mar 07, 2006 9:44 am    Post subject: Reply with quote

pkrish_18,

In short, thats because DB2 optimizer decided that those were the two most efficient ways to retrieve the records for your queries (with and without the order by clause). How the optimizer decides that is a complex story, something that I also do not know everything about.
If you would like your query output to be ordered a certain way, sort on that column.

Regards,
Manas
_________________
There is no path to peace. Peace is the path.
- Mahatma Gandhi (1869-1948)
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group