FirebirdSQL logo

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.

Examples of FIRST/SKIP

  1. The following query will return the first 10 names from the People table:

    select first 10 id, name from People
      order by name asc
  2. The following query will return everything but the first 10 names:

    select skip 10 id, name from People
      order by name asc
  3. And this one returns the last 10 rows.Notice the double parentheses:

    select skip ((select count(*) - 10 from People))
      id, name from People
      order by name asc
  4. This query returns rows 81 to 100 of the People table:

    select first 20 skip 80 id, name from People
      order by name asc