Select Top N record...
 
Notifications
Clear all

Select Top N records from a table or result set  

   RSS

1

I have a table with hundreds of records matching my select criteria, but in the select query I want to limit the number of records returned to top 25. Example: I want to select top 25 highest paid employees from the employee table.

Topic Tags
1 Answer
1

This can be done in several ways in Oracle.

Oracle 12c onwards - Just add "FETCH FIRST 25 ROWS ONLY" at the end of your query.

Example: Select * From employee order by salary desc FETCH FIRST 25 ROWS ONLY;

Other ways of doing this:

using ROWNUM --> Select * From employee where rownum <= 25 order by salary desc;

The same can also be done using other oracle analytic functions like RANK, DENSE_RANK, ROW_NUMBER, PERCENT_RANK, NTILE

Share:
Share this
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •