FETCH FIRST is a row-limiting clause used in SQL implementations that support the SQL-standard-style FETCH syntax.
Understanding standard-style row limiting helps analysts write more portable SQL across different database systems.
Return the first 10 rows after sorting employees by salary.
SELECT
EmployeeName,
Salary
FROM Employees
ORDER BY Salary DESC
FETCH FIRST 10 ROWS ONLY;
FETCH FIRST can be used in reporting, pagination, query testing, and database systems supporting SQL-standard row limiting.
- FETCH FIRST limits returned rows.
- It is useful with ORDER BY.
- It is supported by several database systems.
- Syntax can vary between platforms.
- It can be used for top-N analysis.
What does FETCH FIRST do?
FETCH FIRST limits the number of rows returned by a query.
Why is row limiting useful?
It reduces the result set when only a limited number of records are required.