Oracle select top 10 tips
Question: I know that in
SQL Server you can use the “select top 10” and “select top 100” SQL
clause to automatically fetch the top-n rows from a table.
What is the Oracle equivalent of the “select top 10” command?
Answer: The select top 10 is a
non-ANSI SQL implementation that is unique to SQL Server. It’s
always better to use a standard ANSI solution to a top rows query,
but Oracle has many ways to display the top 10 and top 100 rows from
a table:
select
*
from
(select empno, sal row_number()
over
(order by sal desc) rnk from emp)
where
rnk <= 10;
Oracle top-n query can be satisfied in
several ways: