How to mimic SELECT … LIMIT, OFFSET in OpenEdge SQL?

爷,独闯天下 提交于 2019-12-01 23:21:14

OpenEdge 11.2 added support for OFFSET and FETCH clauses to SQL SELECT queries; versions of OpenEdge below 11.2 do not support OFFSET/FETCH.

From the 11.2 product documentation "SQL Reference" document:

The OFFSET clause specifies the number of rows to skip, before starting to return rows
from the query expression. The FETCH clause specifies the number of rows to return,
after processing the OFFSET clause.

It's worth noting that the TOP and OFFSET/FETCH clauses are mutually exclusive - TOP cannot be used in a query that uses OFFSET or FETCH.

Example queries from the documentation:

Skip the first 10 rows and return the rest of the qualified rows:

SELECT OrderID,OrderDate,custID,filler
FROM dbo.Orders OFFSET 10;

Return the first 10 rows without skipping any:

SELECT OrderID,OrderDate,custID,filler
FROM dbo.Orders
ORDER BY OrderDate DESC, OrderID DESC
FETCH FIRST 10 ROWS ONLY;

Return rows 51 through 60 in the result set of the query:

SELECT OrderID,OrderDate,custID,filler
FROM dbo.Orders
ORDER BY OrderDate DESC, OrderID DESC
OFFSET 50 ROWS FETCH NEXT 10 ROWS ONLY;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!