How do I do top 1 in Oracle? How do I do top 1 in Oracle? oracle oracle

How do I do top 1 in Oracle?


If you want just a first selected row, you can:

select fname from MyTbl where rownum = 1

You can also use analytic functions to order and take the top x:

select max(fname) over (rank() order by some_factor) from MyTbl


SELECT *  FROM (SELECT * FROM MyTbl ORDER BY Fname ) WHERE ROWNUM = 1;


With Oracle 12c (June 2013), you are able to use it like the following.

SELECT * FROM   MYTABLE--ORDER BY COLUMNNAME -OPTIONAL          OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY