是的,这是可能的,但实施将取决于您的 RDBMS。
这是它在 MySQL、PostgreSQL 和 SQLite 中的样子:
select ID, value
from YourTable
where id >= 7
order by id
limit 1
在 MS SQL-Server、Sybase 和 MS-Access 中:
select top 1 ID, value
from YourTable
where id >= 7
order by id
在甲骨文中:
select * from (
select ID, value
from YourTable
where id >= 7
order by id
)
where rownum = 1
在 Firebird 和 Informix 中:
select first 1 ID, value
from YourTable
where id >= 7
order by id
在 DB/2 中(此语法符合 SQL-2008 标准):
select id, value
from YourTable
where id >= 7
order by id
fetch first 1 rows only
在那些具有“窗口”功能的 RDBMS 中(在 SQL-2003 标准中):
select ID, Value
from (
select
ROW_NUMBER() OVER (ORDER BY id) as rownumber,
Id, Value
from YourTable
where id >= 7
) as tmp --- remove the "as" for Oracle
where rownumber = 1
如果您不确定您拥有哪个 RDBMS:
select ID, value
from YourTable
where id =
( select min(id)
from YourTable
where id >= 7
)