FirebirdSQL logo

FIRST, SKIP

Retrieves a slice of rows from an ordered set

Syntax
SELECT
  [FIRST <limit-expression>] [SKIP <limit-expression>]
  FROM ...
  ...

<limit-expression> ::=
    <integer-literal>
  | <query-parameter>
  | (<value-expression>)
Table 1. Arguments for the FIRST and SKIP Clauses
Argument Description

integer-literal

Integer literal

query-parameter

Query parameter place-holder.? in DSQL and :paramname in PSQL

value-expression

A valid expression (returning an integer value)

Note
FIRST and SKIP are non-standard syntax

FIRST and SKIP are Firebird-specific clauses.Use the SQL-standard [fblangref50-dml-select-offsetfetch] syntax wherever possible.

FIRST m limits the output of a query to the first m rows.SKIP n will skip the first n rows of the result set before returning rows.

FIRST and SKIP are both optional.When used together as in “FIRST m SKIP n”, the n topmost rows of the result set are discarded, and the first m rows of the rest of the set are returned.

Characteristics of FIRST and SKIP

  • Any argument to FIRST and SKIP that is not an integer literal or an SQL parameter must be enclosed in parentheses.This implies that a subquery expression must be enclosed in two pairs of parentheses.

  • SKIP 0 is allowed but pointless.

  • FIRST 0 is also allowed and returns an empty set.

  • Negative SKIP and/or FIRST values result in an error.

  • If a SKIP lands past the end of the result set, an empty set is returned.

  • If the number of rows in the result set (or the remainder left after a SKIP) is less than the value of the m argument supplied for FIRST, that smaller number of rows is returned.These are valid results, not error conditions.