Notifications
Clear all
1
13/12/2019 5:35 pm
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.
1 Answer
1
13/12/2019 5:57 pm
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