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 can i select last row( and last five row ) from my table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: How can i select last row( and last five row ) from my table
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    Post subject:
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Fri Jun 29, 2007 8:15 pm    Post subject:
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    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 SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm
No new posts Command UNIQUE CONSTRAINT on any tabl... rohanthengal DB2 2 Thu Aug 18, 2016 3:48 pm
No new posts Updating online Db2 table kishpra DB2 3 Fri Aug 12, 2016 2:44 pm


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