Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How do i get last 10 rows..

Former Member
0 Kudos

Hi ..

Using SELECT ...FROM ...UPTO <n> ROWS.. i can select first 10 rows

of a DB table ,now how can i select last 10 rows of DB table.

Please advise.

jahaan

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

First select all the rows from the DB table

SELECT * FROM db TAB INTO TABLE itab

sort the ITAB by the Key field decending

then take the first 10 records of that sorted ITAB and move into another internal table and use them

<b>Reward points for useful Answers</b>

Regards

Anji

7 REPLIES 7

Former Member
0 Kudos

Hi

First select all the rows from the DB table

SELECT * FROM db TAB INTO TABLE itab

sort the ITAB by the Key field decending

then take the first 10 records of that sorted ITAB and move into another internal table and use them

<b>Reward points for useful Answers</b>

Regards

Anji

Former Member
0 Kudos

SELECT ...FROM ...UPTO <n> ROWS.. ORDER BY <field name> DESCENDING.

regards

shiba dutta

0 Kudos

Hi,

USE ORDERBY In the select statement in such a way that your last 10 rows become your first 10 rows and then use UPTO 10 rows.

Regards,

Sesh

athavanraja
Active Contributor
0 Kudos

last 10 rows on what condition?

create date? if yes then you have to have create date filed in the table to be able to do that

document number?

or some other condition?

Former Member
0 Kudos

*to get the last 10 recod fo the condition

SELECT *

INTO itab FROM <database table>

UP TO 10 ROWS ( where condition ) order by <fieldname> ascending.

regards,

Prabhu

Reward if it is helpful.

Former Member
0 Kudos

Use ORDER BY.

Eg.

SELECT *

INTO itab FROM MARA

UP TO 10 ROWS where werks in so_werks order by MATNR decending.

Former Member
0 Kudos

Wt the exact difference bt select single and select up to one record?