How do I do top 1 in Oracle?

Gold picture Gold · Aug 10, 2010 · Viewed 670k times · Source

How do I do the following?

select top 1 Fname from MyTbl

In Oracle 11g?

Answer

mcpeterson picture mcpeterson · Aug 10, 2010

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