It\'s a common thing in most SQL implementations to be able to select a \"sliding window\" subset of all the rows returned in a query. A common use case for this is paginat
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
.
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;