In Standard SQL, the keyword FIRST appears as part of the FETCH FIRST clause that limits the number of rows returned by a SELECT statement. It is functionally similar to LIMIT (MySQL, PostgreSQL), TOP (SQL Server), or ROWNUM (Oracle) but is fully ANSI-compliant. The clause follows an ORDER BY to guarantee predictable results. Omitting ORDER BY may yield nondeterministic output because the database can return rows in any order. FETCH FIRST can be combined with OFFSET for pagination and supports variations such as FETCH FIRST n ROWS ONLY, FETCH FIRST n ROW ONLY, and FETCH FIRST n PERCENT ROWS ONLY. Some systems also allow WITH TIES to include additional rows that share the same ordering value as the last fetched row.
n
(integer) - positive number of rows to return.ROW
(ROWS) - keyword|||optional plural form, both accepted.PERCENT
(optional in some systems) - keyword – returns the first n percent of rows.WITH TIES
(optional) - keyword – include rows that tie on the last ORDER BY value.LIMIT, OFFSET, TOP, FETCH NEXT, ORDER BY, Pagination
SQL:2008 standard
Both clauses limit the number of rows. FETCH FIRST is usually used for the initial page, while FETCH NEXT reads like natural language when coupled with OFFSET for subsequent pages. Functionally they are identical.
Without ORDER BY the database may return rows in an arbitrary order, making the concept of "first" meaningless. ORDER BY guarantees predictable and repeatable results.
Yes. Many databases accept FETCH FIRST n PERCENT ROWS ONLY to return the top n percent of the ordered result set.
Add WITH TIES after the FETCH clause. The database will include any additional rows that share the same ORDER BY value as the last fetched row.