公告
财富商城
积分规则
提问
发文
2019-01-01 10:50发布
泪湿衣
How do I do the following?
select top 1 Fname from MyTbl
In Oracle 11g?
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
Use:
SELECT x.* FROM (SELECT fname FROM MyTbl) x WHERE ROWNUM = 1
If using Oracle9i+, you could look at using analytic functions like ROW_NUMBER() but they won't perform as well as ROWNUM.
select * from ( select FName from MyTbl ) where rownum <= 1;
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;
You can do something like
SELECT * FROM (SELECT Fname FROM MyTbl ORDER BY Fname ) WHERE rownum = 1;
You could also use the analytic functions RANK and/or DENSE_RANK, but ROWNUM is probably the easiest.
最多设置5个标签!
With Oracle 12c (June 2013), you are able to use it like the following.
Use:
If using Oracle9i+, you could look at using analytic functions like ROW_NUMBER() but they won't perform as well as ROWNUM.
If you want just a first selected row, you can:
You can also use analytic functions to order and take the top x:
You can do something like
You could also use the analytic functions RANK and/or DENSE_RANK, but ROWNUM is probably the easiest.