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

How to Fetch only last 10 records from the table


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top