Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

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

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: i want to fetch first 5 rows and last 5 rows in a table?
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    Post subject: Re: i want to fetch first 5 rows and last 5 rows in a table?
Reply with quote

Try using CURSOR and FETCH options

refer to

http://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    Post subject: where i need to give this fetch statement
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    Post subject: Re: i want to fetch first 5 rows and last 5 rows in a table?
Reply with quote

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

Refer to http://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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts To display values of multiple rows in... vinu78 DB2 2 Thu Mar 09, 2017 1:20 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts Join of more than one table dibyendumandal11111 DB2 6 Mon Feb 13, 2017 11:36 pm
This topic is locked: you cannot edit posts or make replies. DB2 query Using Recursion, Converting... smilewithashu2 DB2 3 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us