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 > rownum equivalent in db2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-11-05, 12:33
skumbhan skumbhan is offline
Registered User
 
Join Date: Sep 2005
Posts: 9
rownum equivalent in db2

hi

i am trying to extract rows between 10,000 and 20,000. is there a way to do it...

i know for extracting rows from 1 to 10,000 u can specify fetch first 10000 rows only.

But to get rows between 10,000 and 20,000 is there a way?

sam
Reply With Quote
  #2 (permalink)  
Old 11-11-05, 15:21
wangzhonnew wangzhonnew is offline
Registered User
 
Join Date: Nov 2005
Location: Toronto
Posts: 65
i don't think there's any way to do that....
Reply With Quote
  #3 (permalink)  
Old 11-11-05, 16:28
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Code:
select ... from (select ..., row_number() over (order by ...) as rownum from ...) as tmp
where tmp.rownum between ....
Reply With Quote
  #4 (permalink)  
Old 11-12-05, 06:07
grahammartin grahammartin is offline
Registered User
 
Join Date: Apr 2005
Posts: 41
Sample code, using syscat.tables.....

with t as (select card, row_number() over() as col2 from syscat.tables order by 1 desc) select * from t where col2 between 11 and 20 order by 2 asc

Graham Martin
http://www.ibm.com/software/data/db2/migration/
Reply With Quote
  #5 (permalink)  
Old 11-12-05, 09:17
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by grahammartin
Sample code, using syscat.tables.....

with t as (select card, row_number() over() as col2 from syscat.tables order by 1 desc) select * from t where col2 between 11 and 20 order by 2 asc
There really needs to be a ORDER BY in the OVER function, otherwise one will have no idea what rows 11 thru 20 are, and the order will not be be repeatable (one will not get the same rows every time), and the query will make no sense.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
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