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 Loading data to table gives wrong for... Raghu navaikulam DB2 18 Thu Jul 13, 2017 2:11 pm
No new posts compare 2 rows within the same file ram_vizag SYNCSORT 7 Wed Jun 14, 2017 12:34 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts unload data from table with lob columns farhad_evan DB2 1 Sat Apr 22, 2017 1:32 pm
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm


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