Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Have to fetch only 98th and 99th row only

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Have to fetch only 98th and 99th row only
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: 680
Location: NJ

PostPosted: Fri Jun 16, 2006 7:26 pm    Post subject: DB2 Query
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Wed Jun 21, 2006 4:10 am    Post subject: Re: Have to fetch only 98th and 99th row only
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    Post subject:
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    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 Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts Multi row fetch - "for read only... Nileshkul DB2 3 Sun Aug 14, 2016 12:52 am
No new posts JCL to fetch schedule status from act... parasmalik20 CA Products 1 Thu Jun 02, 2016 7:11 pm
No new posts ABEND due to FETCH FAILED jackzhang75 ABENDS & Debugging 17 Thu Mar 10, 2016 3:08 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us