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

how to write a SQL Query for selecting last 2 records


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

New User


Joined: 15 Sep 2006
Posts: 5

PostPosted: Fri Sep 15, 2006 5:23 am
Reply with quote

hai freinds,

this is prasad, can u plz help in this,

how to write a SQL Query for selecting only last 2 records in any table
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


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

PostPosted: Fri Sep 15, 2006 10:52 am
Reply with quote

See this...
Back to top
View user's profile Send private message
chandu_usa99
Warnings : 2

New User


Joined: 21 Sep 2006
Posts: 3

PostPosted: Tue Sep 26, 2006 3:09 am
Reply with quote

Hey,
If it is clustered it is very easy.

Say your querry like this

SELECT *
FROM OEDCOD.TED_MQ_SERIES_CNT B
ORDER BY MQCNT_CLIENT_NBR DESC
,MQCNT_ADD_DATE DESC
,MQCNT_MSG_MAX_SIZE DESC
,MQCNT_MQ_MSG_TYP DESC
FETCH FIRST 2 ROWS ONLY
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:07 pm
Reply with quote

Hi
see Query
Select * from 'tablename'

order by primary key DESC
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 Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top