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

How can i select last row( and last five row ) from my table


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

New User


Joined: 04 May 2007
Posts: 13
Location: pune

PostPosted: Fri Jun 29, 2007 2:57 pm
Reply with quote

hello,
plz tell me how can i select last row( and last five row ) from my table , i dont know how-many rows in my table plz give me proper example.
Back to top
View user's profile Send private message
ParagChouguley

Active User


Joined: 03 Feb 2007
Posts: 175
Location: PUNE(INDIA)

PostPosted: Fri Jun 29, 2007 4:20 pm
Reply with quote

Hi,

What do you exactly mean by
Quote:
plz tell me how can i select last row( and last five row ) from my table


Actually, you have to arrange the rows using 'ORDER BY' clause as you want them and then select them.

Please refer to following SQL statements.

SELECE column_name FROM table_name
WHERE column_name = VALUE
ORDER BY column_name DESC

Use ASC/DESC for ascending/descending.

Do search on the forum for more results.

--Parag
Back to top
View user's profile Send private message
saiprasadh

Active User


Joined: 20 Sep 2006
Posts: 154
Location: US

PostPosted: Fri Jun 29, 2007 5:17 pm
Reply with quote

hi pankajupadhyay

You can use the below query also,

Code:
SELECE column_name FROM table_name
WHERE column_name = VALUE
ORDER BY column_name DESC
FETCH First 5 rows only;


Thanks
Sai
Back to top
View user's profile Send private message
Nimesh.Srivastava

New User


Joined: 30 Nov 2006
Posts: 78
Location: SINGAPORE

PostPosted: Fri Jun 29, 2007 7:34 pm
Reply with quote

pankajupadhyay,
Order By clause can only help if the column values of the column in question is generated sequentially or timestamp. Please specify clearly how is column values generated for which you want the last 5 rows, i.e. how do specify a row in the table to be the last or first.
Thanks
Nimesh
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jun 29, 2007 8:15 pm
Reply with quote

Hello,

What is your definition of the "last" row?

In a sequential file, the last record is easily defined, but your questin is not about a sequential file.
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 Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top