In the most recent version of Oracle, use order by
and fetch
:
(在Oracle的最新版本中,使用order by
和fetch
:)
select e.*
from employees e
order by hire_date desc
fetch first 1 row only;
In earlier versions, this is often implemented using a subquery:
(在早期版本中,通常使用子查询来实现:)
select e.*
from (select e.*
from employees e
order by hire_date desc
)
where rownum = 1;
Both of these return only one row -- your question is in the singular.
(两者都只返回一行-您的问题是单数形式。)
There are variations that return all the most recent employees if there are duplicates. (如果有重复,有一些变体会返回所有最近的雇员。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…