Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

how to write a SQL Query for selecting last 2 records

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: how to write a SQL Query for selecting last 2 records
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: 1452
Location: Chicago, IL

PostPosted: Fri Sep 15, 2006 10:52 am    Post subject: Re: how to write a SQL Query for selecting last 2 records
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    Post subject: Last 2 rows
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    Post subject:
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    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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us