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 > Pagination or records per page

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-16-04, 10:40
tpass001 tpass001 is offline
Registered User
 
Join Date: Jun 2004
Posts: 3
Exclamation Pagination or records per page

:: Environment DB2 V7.1.1 on Z/OS. ::

I am looking for a sql query that would return rows 20 through 30 of a query.

For example
select * from ( select a.*, rownum rnum from (select job, empno from emp order job asc) a )where rnum>=20 and rnum<30

This is in oracle, but is there a way to do this using db2 v7.1.1 on zos?

Please let me know, I have been looking for this for a while now and have come to believe that there is no solution to this.

Thanks.

TP.
Reply With Quote
  #2 (permalink)  
Old 11-17-04, 15:39
Santosh Kumar Santosh Kumar is offline
Registered User
 
Join Date: Sep 2004
Posts: 6
I'm not sure if the EXCEPT operator is available in DB2 V7 on z/OS, but if it is, you can try the following query --

select * from (select * from emp fetch first 5 rows only) as temp1
EXCEPT
select * from (select * from emp fetch first 2 rows only) as temp2
;

This query would give rows 3 thru 5. An assumption made is that the table has a primary key or the column-list given by SELECT * forms a unique key across table. This would ensure desired results given the functioning of EXCEPT.

I have tested this successfuly on DB2 V8.1 on Unix.
Reply With Quote
  #3 (permalink)  
Old 11-17-04, 17:31
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by Santosh Kumar
This would ensure desired results given the functioning of EXCEPT.
I think this will only ensure that you'll get any 3 rows out of any 5. This kind of query will also ensure horrible performance given a table of a decent size.
Reply With Quote
  #4 (permalink)  
Old 11-18-04, 21:24
Santosh Kumar Santosh Kumar is offline
Registered User
 
Join Date: Sep 2004
Posts: 6
You are right, you got to do 'order by' to get the right rows --

select * from (select * from emp order by job fetch first 5 rows only) as temp1
EXCEPT
select * from (select * from emp order by job fetch first 2 rows only) as temp2
;

Performance would definitely be an issue for a huge table.
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