How to sort and retrevie rows without using ORDER BY clause

Ask question on - DataBase Concepts, IBM Mainframe DB2, DB2/UDB, DB2 Tools, SQL , DB2 programming with languages like COBOL, PL1.

Moderators: Kalicharan, Moderator Group

Post Reply
srini0907
Member
Posts: 1
Joined: Tue Nov 06, 2012 11:09 am

How to sort and retrevie rows without using ORDER BY clause

Post by srini0907 » Tue Nov 06, 2012 11:24 am

Hi,

I have a requirement to retreive rows using cursor from DB2 table using the curosr which is as below:

Select C1, C2,C3, C4, C5, C6..
where C1= :v1
and C2 = :v2
and C3 = ( Select max(C3)
where C1= :v1
and C2 = :v2
and C4 = :v4
)
ORDER BY C1 ASC and C2 DESC.
Lets say the query retrieves 100 rows.
But my program can only handle 50 rows.
so my program in the first instance should retreive first 50 rows in the first instance and the remaining 50 in the next instance.

Could you please help me with this.

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India

Post by Anuj Dhawan » Tue Nov 06, 2012 3:56 pm

Suggtest you try this and see what happens?
Regards,
Anuj

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa

Post by DikDude » Tue Nov 06, 2012 10:18 pm

Suggtest you try this and see what happens?
As posted, it will retrieve 100 rows . . ., will it not?

Is this running in a program that should process the first 50 and then the next 50?

If so, you need to keep track of "where you are" and on the second time thru, start with the "next" row.

Another way you might consider is using a multi-row fetch.

And why does the topic title say Not to use ORDER BY?
Have a good one

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others