IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

i want to fetch first 5 rows and last 5 rows in a table?


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
babu_hi

New User


Joined: 11 Apr 2006
Posts: 93

PostPosted: Tue Nov 21, 2006 11:50 am
Reply with quote

I have table that contain 50 rows,My requirement is i want fetch first 5 rows and last 5 rows in the table?
Back to top
View user's profile Send private message
MFRASHEED

Active User


Joined: 14 Jun 2005
Posts: 186
Location: USA

PostPosted: Tue Nov 21, 2006 9:21 pm
Reply with quote

Try using CURSOR and FETCH options

refer to

publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/dsnsqj10/5.57?ACTION=MATCHES&REQUEST=fetch&TYPE=FUZZY&SHELF=&DT=20040216135741&CASE=&searchTopic=TOPIC&searchText=TEXT&searchIndex=INDEX&rank=RANK&ScrollTOP=FIRSTHIT#FIRSTHIT

Look for options like:

Code:

FETCH FIRST ROWSET FOR 5     | Cursor is positioned on a rowset of   
ROWS                         | size 5, consisting of rows 1, 2, 3, 4,
                             | and 5.                                 


Code:

+------------------------------+-----------------------------------------|
| FETCH LAST ROWSET FOR 2 ROWS | Cursor is positioned on a rowset of     |
|                              | size 2, consisting of rows 14 and 15.   |

FETCH ROWSET STARTING AT     | Cursor is positioned on a rowset of   
ABSOLUTE 2 FOR 3 ROWS        | size 3, consisting of rows 2, 3, and 4.

Back to top
View user's profile Send private message
chettiyar
Currently Banned

New User


Joined: 27 Sep 2006
Posts: 6
Location: india,kerala

PostPosted: Wed Nov 22, 2006 12:24 pm
Reply with quote

hi,
Thank u very much for porviding a good knowledge sharing topic.
Whether i need to specify these statements inside the declare cursor statement or any where else................................

special thanks to MFRASHEED
Back to top
View user's profile Send private message
MFRASHEED

Active User


Joined: 14 Jun 2005
Posts: 186
Location: USA

PostPosted: Wed Nov 22, 2006 11:23 pm
Reply with quote

You would need to first declare CURSOR with 'WITH ROWSET POSITIONING'.

Refer to publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/dsnsqj10/5.42?ACTION=MATCHES&REQUEST=CURSOR&TYPE=FUZZY&SHELF=&DT=20040216135741&CASE=&searchTopic=TOPIC&searchText=TEXT&searchIndex=INDEX&rank=RANK&ScrollTOP=FIRSTHIT#FIRSTHIT

and other statements to limit row selection will be part of actual FETCH statement. In earlier link i provided, page to then end and there are some good examples of FETCH.

I am glad i was able to help.
Back to top
View user's profile Send private message
babu_hi

New User


Joined: 11 Apr 2006
Posts: 93

PostPosted: Thu Nov 23, 2006 10:21 am
Reply with quote

Hi MFRASHEED,

Thanks for ur reply. i have executed this query it's working fine.

Regards
Babu
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top