You can include an ORDER BY clause in a SELECT statement
with a FIRST clause to return rows that contain the highest or lowest
values for a specified column. The following query shows a query that
includes an ORDER BY clause to return (by alphabetical order) the
first five states contained in the state table. The query,
which is the same as Query except for
the ORDER BY clause, returns a different set of rows than Query.
The following query shows how to use a FIRST clause in
a query with an ORDER BY clause to find the 10 most expensive items
listed in the stock table.
Applications can use the SKIP and FIRST keywords of the
Projection clause, in conjunction with the ORDER BY clause, to perform
successive queries that incrementally retrieve all of the qualifying
rows in subsets of some fixed size (for example, the maximum number
of rows that are visible without scrolling a screen display). You
can accomplish this by incrementing the offset parameter of
the SKIP clause by the max parameter of the FIRST clause after
each query. By imposing a unique order on the qualifying rows, the
ORDER BY clause ensures that each query returns a disjunct subset
of the qualifying rows.
The following query shows a query that includes SKIP,
FIRST, and ORDER BY specifications to return (by alphabetical order)
the sixth through tenth states in the state table, but not
the first five states. This query resembles Query, except that
the SKIP 5 specification instructs the database server to returns
a different set of rows than Query.
If you use the SKIP, FIRST, or LIMIT keywords, you must
take care to specify parameters that correspond to the design goals
of your application. If the offset parameter of skip is larger
than the number of qualifying rows, then any FIRST or LIMIT specification
has no effect, and the query returns nothing.