If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Selecting only few rows from within a resultset

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-05-04, 04:30
ashokcm ashokcm is offline
Registered User
 
Join Date: Feb 2004
Posts: 6
Question Selecting only few rows from within a resultset

Inorder to implement page navigation and sorting,I am querying the DB and in my SP I
1.Select all the records that match a particular criteria
2.Sort the result set

Now i need to get rows 21-40 (say) from the sorted resultset(not the table).Can anyone tell me how to do this?

I tried using the rownumber() method,but it seems that the rownumbers are corresponding to the row entry in the table and not the resultset.

thanx in advance....
Reply With Quote
  #2 (permalink)  
Old 02-05-04, 04:34
nitingm nitingm is offline
Registered User
 
Join Date: Jul 2003
Location: Austin, TX, USA
Posts: 278
Fetch First N Rows

Hi,

There is an option of using fetch first 'n' rows only.

Can you push the resultset into a temporary table and then try the fetch first rows only option.

Please also provide more details on your process being followed, and the DB2 version, fixpacks and OS that you are using.

Cheers

Nitin.
__________________
HTH

Nitin

Ask the experienced rather than the learned
Reply With Quote
  #3 (permalink)  
Old 02-05-04, 04:36
ashokcm ashokcm is offline
Registered User
 
Join Date: Feb 2004
Posts: 6
Not first n,but from anywhere

I dont want to fetch first n,but i need to fetch in between two values say 21-40 or 41-60 and the like.Can u help me? Coz it is very urgent!
thanx in advance.....
Reply With Quote
  #4 (permalink)  
Old 02-05-04, 04:39
ashokcm ashokcm is offline
Registered User
 
Join Date: Feb 2004
Posts: 6
Db2 version 7,OS is Win2K.......

Db2 version 7,OS is Win2K.......
Reply With Quote
  #5 (permalink)  
Old 02-05-04, 04:42
nitingm nitingm is offline
Registered User
 
Join Date: Jul 2003
Location: Austin, TX, USA
Posts: 278
TryThis

hi Ashok,

Will populating the result set into a temporary table and then using the rownumber() on that temporary table help?

As you said that the rownumber() works on the table, guess that should solve your purpose temporarily, till you get a better solution.

HTH

Nitin.
__________________
HTH

Nitin

Ask the experienced rather than the learned
Reply With Quote
  #6 (permalink)  
Old 02-05-04, 04:45
ashokcm ashokcm is offline
Registered User
 
Join Date: Feb 2004
Posts: 6
I'm trying that

I was just trying that out.Is there no other solution? As there is an option to fetch first n,i thought there will be an option to select from in between.....
Reply With Quote
  #7 (permalink)  
Old 02-05-04, 13:54
chuzhoi chuzhoi is offline
Registered User
 
Join Date: Dec 2002
Posts: 134
Re: I'm trying that

Quote:
Originally posted by ashokcm
I was just trying that out.Is there no other solution? As there is an option to fetch first n,i thought there will be an option to select from in between.....
The only solutions:
1. row_number() over(...)
2. fetch first 40 and skip first 20 (acceptible for small numbers)
Reply With Quote
  #8 (permalink)  
Old 02-05-04, 23:18
ashokcm ashokcm is offline
Registered User
 
Join Date: Feb 2004
Posts: 6
how to skip first 20?

but how do i skip first 20?
Reply With Quote
  #9 (permalink)  
Old 02-06-04, 01:19
chuzhoi chuzhoi is offline
Registered User
 
Join Date: Dec 2002
Posts: 134
Re: how to skip first 20?

Quote:
Originally posted by ashokcm
but how do i skip first 20?
In the code first do resultset.next() 20 times and than start processing

It sounds dumb, but it may be a good idea for a small page numbers. Otherwise you need to materialize (or numerate) 1000's of records (for row_number or temp table)
Reply With Quote
  #10 (permalink)  
Old 02-06-04, 01:24
ashokcm ashokcm is offline
Registered User
 
Join Date: Feb 2004
Posts: 6
thank you

ok....thank you......i used a temp table....and it was successful......
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On