View previous topic :: View next topic
|
Author |
Message |
aryanpa1
New User
Joined: 26 May 2007 Posts: 45 Location: Chennai
|
|
|
|
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 |
|
|
saiprasadh
Active User
Joined: 20 Sep 2006 Posts: 154 Location: US
|
|
|
|
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 |
|
|
Prasanthhere
Active User
Joined: 03 Aug 2005 Posts: 306
|
|
|
|
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
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 |
|
|
sanjayis01 Warnings : 1 New User
Joined: 13 Jun 2007 Posts: 55 Location: banaglore
|
|
|
|
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
You can't execute a where against the table name. You have from X and where X. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
aryanpa1
New User
Joined: 26 May 2007 Posts: 45 Location: Chennai
|
|
|
|
Thank you....every body....
It is just like homework dont have any business requirement and ur suggestions worked. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome |
|
Back to top |
|
|
|