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

Have to fetch only 98th and 99th row only


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

New User


Joined: 16 Jun 2006
Posts: 4

PostPosted: Fri Jun 16, 2006 12:46 pm
Reply with quote

I have a DB2 table ,I donot know the structure of the table,but i know there are 100 rows.Now i have to fetch only 98th and 99th row only.How can we realise this by query ?
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 677
Location: NJ

PostPosted: Fri Jun 16, 2006 7:26 pm
Reply with quote

Deepak,

It's a difficult case may i know your exact requirement. where you are suppose to utilize your above scenario? icon_sad.gif
Back to top
View user's profile Send private message
anamikak

New User


Joined: 10 May 2006
Posts: 64
Location: Singapore

PostPosted: Tue Jun 20, 2006 8:07 am
Reply with quote

1. Find out the primary key of your table from SYSIBM.SYSCOLUMS.
2. then try out the fetch first n records as:

Select * from 'tablename'

order by primary key DESC.

fetch first 3 rows only.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Wed Jun 21, 2006 4:10 am
Reply with quote

Code:
SELECT * FROM
(SELECT * FROM <CREATOR>.<TABLE> FETCH FIRST N ROWS ONLY)
FETCH LAST ROW ONLY;


Replace N with the row-number you like to retrieve.
Back to top
View user's profile Send private message
anoopkhetan

New User


Joined: 22 Sep 2006
Posts: 3
Location: mumbai

PostPosted: Tue Sep 26, 2006 2:02 pm
Reply with quote

Hi,
See Query

Select * from 'tablename'

order by primary key DESC where Primary key < max(primary key)

fetch first 2 rows only

Anoop
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 Fetch data from programs execute (dat... DB2 3
No new posts Code Multi Row fetch in PL1 program PL/I & Assembler 1
No new posts Need to fetch data from so many DB2 t... DB2 9
No new posts fetch the record number from FMNMAIN ... CLIST & REXX 10
No new posts Fetch the Dataset names from inside m... TSO/ISPF 18
Search our Forums:

Back to Top