How to Limit Oracle Query Result

You may use below command to limit the query result. Taking on example for SAP table E070, column E070.
The query will list out the latest 8 rows inserted to the E070 table, specifically on TRKORR column.
select TRKORR from SAPSR3.E070 where rownum <= 8;
 
TRKORR
------------------------------------------------------------
DEVK900010
DEVK900011
DEVK900012
DEVK900013
DEVK900014
DEVK900015
DEVK900016
DEVK900017
If you want to list the result of the first 8 rows or last 8 rows, you may need to use the ORDER by query. The command will sort the result by ascending or descending order.
#DESCENDING ORDER
 
SQL> select TRKORR from (select TRKORR from SAPSR3.E070
order by TRKORR DESC) where rownum <=8;
 
TRKORR
------------------------------------------------------------
DEVK900020
DEVK900021
DEVK900022
DEVK900023
DEVK900024
DEVK900025
DEVK900026
DEVK900027
 
8 rows selected.
#ASCENDING ORDER
 
SQL> select TRKORR from (select TRKORR from SAPSR3.E070
order by TRKORR ASC) where rownum <=8;
 
TRKORR
------------------------------------------------------------
DEVK900001
DEVK900002
DEVK900003
DEVK900004
DEVK900005
DEVK900006
DEVK900007
DEVK900008
 
8 rows selected.
SHARE

sangeethakumar

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment