MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

first 5 records from a db2 table

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
jagan
Beginner


Joined: 27 Jan 2003
Posts: 5
Topics: 4

PostPosted: Mon Feb 17, 2003 3:56 am    Post subject: first 5 records from a db2 table Reply with quote

how to retrive first 5 records from a db2 table
pl let me know the answer
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Mon Feb 17, 2003 6:49 am    Post subject: Reply with quote

jagan,

If you have db2 version 7 then you can use the following query to get 5 records of the table.

Code:

SELECT *
  FROM TABLE
  FETCH FIRST 5 ROWS ONLY
  ;


Check this link for a detailed explanation of FETCH FIRST

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH11/4.4.7?SHELF=&DT=20010718164132

Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jagan
Beginner


Joined: 27 Jan 2003
Posts: 5
Topics: 4

PostPosted: Tue Feb 18, 2003 2:08 am    Post subject: Reply with quote

thanks kolusu
is it possible to get last 5 records from a table?in the same way?
Back to top
View user's profile Send private message Yahoo Messenger
Himesh
CICS Forum Moderator
CICS Forum Moderator


Joined: 20 Dec 2002
Posts: 80
Topics: 21
Location: Chicago

PostPosted: Tue Feb 18, 2003 3:15 am    Post subject: Reply with quote

Jagan,

If you had referred to the same link that Kolusu had posted, you would have come across the following statement:

Quote:

If both the FETCH FIRST clause and the ORDER BY clause are specified, the ordering is performed on the entire result set prior to returning the first n rows.


So, you could fetch the last 5 rows by using an ORDER BY DESC clause in your SQL.

Example:

Code:

SELECT *
  FROM TABLE
WHERE Col1 = :host-var
ORDER BY COL1 DESC
  FETCH FIRST 5 ROWS ONLY
  ;


regards,
Himesh
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group