Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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 Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm
No new posts how to see when the last read access ... Mike 1304 DB2 1 Tue Sep 12, 2017 7:52 pm
No new posts PC (UTF-8) -> z/OS (EBCDIC) -> ... prino All Other Mainframe Topics 4 Fri Sep 01, 2017 1:47 am
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us