Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Prob with ORDER BY switching from a CURSOR to Single-Select

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Melwyn Mark DSouza

New User


Joined: 02 Jun 2009
Posts: 2
Location: India

PostPosted: Tue Jun 02, 2009 3:23 pm    Post subject: Prob with ORDER BY switching from a CURSOR to Single-Select
Reply with quote

Hi,

I have a cursor declared as follows:

Code:

SELECT A.COL1,
       A.EFF_DT,
       A.END_DT
  FROM  TABLEA A
WHERE A.COL1='X'
    AND A.COL2 ='Y'
ORDER BY END_DT DESC



I am required to improve the performance of this query. Also, in the code it so happens that only the first row retrieved is required. So I tried the following in a single-select statement:
Code:

SELECT A.COL1,
       A.EFF_DT,
       A.END_DT
  FROM  TABLEA A
WHERE A.COL1='X'
    AND A.COL2 ='Y'
ORDER BY END_DT DESC
FETCH FIRST 1 ROW ONLY



But now the PROBLEM is that the first row retrieved is not the same.

There is a non-unique index on COL1. Primary key is composite of several columns, none of which are used in this query.

I have even tried using MAX in query and sub-query but to no avail.

Any pointers?

Thanks & Regards,
Melwyn
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jun 02, 2009 3:55 pm    Post subject:
Reply with quote

Well either upgrade to version 8, where you can have an ORDER BY in a singleton select

or

go back to the CURSOR
use OPTIMIZE for 1 ROW.
Back to top
View user's profile Send private message
Melwyn Mark DSouza

New User


Joined: 02 Jun 2009
Posts: 2
Location: India

PostPosted: Tue Jun 02, 2009 4:05 pm    Post subject:
Reply with quote

Thanks Dick.

In DB2 Platinum I see

DB2 VERSION :V9R1M0

Thanks & Regards,
Melwyn
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Data replication from multiple Db2 ta... kishpra DB2 5 Mon Mar 27, 2017 9:58 pm
No new posts Splitting of single report to seperat... abdulrafi TSO/ISPF 4 Mon Mar 27, 2017 3:59 pm
No new posts Getting -504 Cursor Name GTT-ARTS-CUR... Robin Sulsona DB2 2 Fri Mar 17, 2017 1:43 am
No new posts Append data from two files into a sin... Praveen04 DFSORT/ICETOOL 5 Thu Mar 16, 2017 7:29 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us