我试图使用以下代码从表中选择最高ID及其描述。但是它一直返回null。请有人建议我哪里出错了
Select ID, Description
FROM STOPS
where Description = (select MAX(ID)
from STOPS);
使用order by
和相当于fetch first 1 row only
:
select s.*
from stops s
order by s.id desc
fetch first 1 row only;
这是ANSI标准语法。并非所有数据库都支持fetch first
,有些使用limit
,select top
或rownum
。