IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Retrieve the second 50,000 rows.


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
aryanpa1

New User


Joined: 26 May 2007
Posts: 45
Location: Chennai

PostPosted: Wed Aug 29, 2007 1:23 pm
Reply with quote

Hi ,
I have a big db2 table which contain 2 lakh rows.
First I need to retrieve first 50,000 rows.
Second I need to retrieve next 50,000 rows.
and so on.......

Can anybody suggest me queries for the above conditions.Thank you
Back to top
View user's profile Send private message
saiprasadh

Active User


Joined: 20 Sep 2006
Posts: 154
Location: US

PostPosted: Wed Aug 29, 2007 2:28 pm
Reply with quote

Hi Aryanpa1,


My Suggestion is unload first 1 Lakh rows, After that use a SORT step to skip the first 50000 records.



Thanks
Sai
Back to top
View user's profile Send private message
Prasanthhere

Active User


Joined: 03 Aug 2005
Posts: 306

PostPosted: Wed Aug 29, 2007 2:53 pm
Reply with quote

For selecting the first 50000 rows you can use like

Select * from tablename where condition fetch first 50000 rows only

for selecting the next 50000 rows

you should have the row number and giving a greater than condition
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Wed Aug 29, 2007 5:21 pm
Reply with quote

There is no such thing as the first, second, or last 50000 rows in a database. The order can change on you from query to query without an order by clause. See previous posts by quite a few people.
Back to top
View user's profile Send private message
sanjayis01
Warnings : 1

New User


Joined: 13 Jun 2007
Posts: 55
Location: banaglore

PostPosted: Wed Aug 29, 2007 5:39 pm
Reply with quote

Hi

Try this this may work for you


select * from X where X <=10 or (X >=20 and X<=30) or (X>=40 and X<=50)
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Wed Aug 29, 2007 6:04 pm
Reply with quote

You can't execute a where against the table name. You have from X and where X.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Aug 29, 2007 7:20 pm
Reply with quote

Hello,

As has been pointed out, there is no such thing as the "first n rows" in an active table.

The only way you can guarantee consistent results from data that may change "on the fly" (as most tables do) is to unload the table in some sequence and then do as also previously suggested and work with the unloaded qsam file. You can use/skip as many as you like.

Is there some business requirement for this, is it homework, or?
Back to top
View user's profile Send private message
aryanpa1

New User


Joined: 26 May 2007
Posts: 45
Location: Chennai

PostPosted: Thu Aug 30, 2007 10:25 am
Reply with quote

Thank you....every body....
It is just like homework dont have any business requirement and ur suggestions worked.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Aug 30, 2007 6:21 pm
Reply with quote

You're welcome icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Using Java/C/C++ to retrieve dataset ... Java & MQSeries 6
No new posts Convert single row multi cols to sing... DFSORT/ICETOOL 6
No new posts Compare latest 2 rows of a table usin... DB2 1
Search our Forums:

Back to Top