By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,586 Members | 2,445 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,586 IT Pros & Developers. It's quick & easy.

Pagination in DB2

P: 2
Hi ,

I need help.

1: Im executing a query which throws some 1000 rows. Out of which only 20 rows shuld be displayed per page on the Front end at a time.
So i need to apply the concept of pagination here. Which means these 1000 rows should be distributed into number of pages (each containing 20 rows). I should display only those rows in the page which the user has selected.
How do i do this. Please give me some example also please.
Nov 15 '07 #1
Share this Question
Share on Google+
1 Reply


docdiesel
Expert 100+
P: 297
Hi,

if your SELECT is rather static, you could create a view first:

Expand|Select|Wrap|Line Numbers
  1. Create View
  2.   blog.entries_last1000
  3. as
  4.   Select
  5.     ROW_NUMBER() OVER(order by date,time desc) as ROWNO,
  6.     date,time,title
  7.   From
  8.     blog.entries_all
  9.   Fetch
  10.     first 1000 rows only;
Then do a select based on multiples of 20, e.g for the 11th page.

Expand|Select|Wrap|Line Numbers
  1. Select
  2.   rowno,date,time,title
  3. from
  4.   blog.entries_last1000
  5. where
  6.   rowno > 20 * (11 - 1)
  7. fetch
  8.   first 20 rows only ;
  9.  
(Besides, if frequently read while data is changing infrequently, I'd rather set up a cronjob and store those 1000 rows in a separate table.)

Regards,

Bernd
Nov 15 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.