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

后端 未结 1 372
灰色年华
灰色年华 2021-01-20 10:52

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

相关标签:
1条回答
  • 2021-01-20 11:16

    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;
    
    0 讨论(0)
提交回复
热议问题