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
 
How to Fetch only last 10 records from the table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
nandakumar
Warnings : 2

New User


Joined: 05 May 2005
Posts: 50

PostPosted: Wed Jun 01, 2005 9:16 pm    Post subject: How to Fetch only last 10 records from the table
Reply with quote

hi,
this is nandakumar,
Any one can plz tell me the db2 sqlquery for the following:

if a table contains 100 rows (that 100 records),how to fetch the
only last 10 records from the table(from 91st rec to 100th rec)
Back to top
View user's profile Send private message

harinadh

New User


Joined: 01 Sep 2004
Posts: 18

PostPosted: Thu Jun 02, 2005 9:39 am    Post subject:
Reply with quote

Suppose the table contains the fields Eno, Ename and Eno is the primary key then the query is

select * from Emp order by Eno desc fetch first 100 rows only;
Back to top
View user's profile Send private message
kumar_jalluri

New User


Joined: 02 Jun 2005
Posts: 24
Location: PUNE

PostPosted: Thu Jun 02, 2005 1:26 pm    Post subject:
Reply with quote

if the table contains any field like serial number or emp number in serial order,

write the query

select * from emp order by sno desc fetch first 10 rows only.
Back to top
View user's profile Send private message
deepak dixit

New User


Joined: 02 Jun 2005
Posts: 1

PostPosted: Thu Jun 02, 2005 2:32 pm    Post subject:
Reply with quote

hello sir,
sppose you have a three fields a b c in a table in some cases b is blank. at the time of disply if b is blank then the memory of b should be removed and a and c must be cocatenate lilke firstname middlename lastname. if middle name is not there. in db2 and db2 to vsm also.its a big proble for me i have allready face 2 times this problem if knows please tell me.
thanks
Back to top
View user's profile Send private message
badal

New User


Joined: 05 Sep 2004
Posts: 21

PostPosted: Sun Jun 05, 2005 10:17 pm    Post subject: Re: How to Fetch only last 10 records from the table
Reply with quote

Hi,
use the function ROWID. all of u r problem will be solved.
hope u can find the query from udb book.
thanks.
Back to top
View user's profile Send private message
laxmi

New User


Joined: 24 May 2005
Posts: 9

PostPosted: Mon Jun 06, 2005 3:24 pm    Post subject: hai,
Reply with quote

By using scrollable cursors it is possible
by this we can move forward and backward and we can retreive specified set of records

to fetch last 10 records u have to use relagtive n option with FETCH

DECLARE CSR1 SENSITIVE STATIC SCROLL CURSOR
FOR SELECT FIRSTNAME , LASTNAME FROM EMP ;

FETCH RELATIVE 10 INTO :ARRAY

WHERE ARRAY IS WORKING STOREAGE VARIABLE DECLARED AS ARRAY
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 Inefficient BUILD - VB records paddin... Daniel Prosser SYNCSORT 9 Thu Dec 14, 2017 3:52 pm
No new posts ISSUE IN copying Sequential file reco... thesumitk JCL & VSAM 2 Wed Dec 13, 2017 3:07 pm
No new posts query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts Merging 2 records at multiple rows wi... Bijesh DFSORT/ICETOOL 2 Wed Dec 06, 2017 1:50 am
This topic is locked: you cannot edit posts or make replies. Cobol to fetch the content by using s... arunc55 COBOL Programming 4 Fri Nov 17, 2017 1:25 pm

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