fetch-first-clause

Click to skip syntax diagram
Read syntax diagramSkip visual syntax diagram                .-1-------.
>>-FETCH FIRST--+---------+--+-ROW--+--ONLY--------------------><
                '-integer-'  '-ROWS-'
 

The fetch-first-clause sets a maximum number of rows that can be retrieved. It lets the database manager know that only integer rows should be made available to be retrieved, regardless of how many rows there might be in the result table when this clause is not specified. An attempt to fetch beyond integer rows is handled the same way as normal end of data (SQLSTATE 02000). The value of integer must be a positive integer (not zero).

Limiting the result table to the first integer rows can improve performance. The database manager will cease processing the query once it has determined the first integer rows.

If both the order-by-clause and fetch-first-clause are specified, the FETCH FIRST operation is always performed on the ordered data. Specification of the fetch-first-clause in a select-statement makes the result table read-only. A read-only result table must not be referred to in an UPDATE or DELETE statement. The fetch-first-clause cannot appear in a statement containing an UPDATE clause.