FETCH FIRST is used with row-limiting syntax to return a specified number of rows from a query result.
Understanding different row-limiting techniques helps analysts work across database platforms.
Return the first five employees after sorting by salary.
SELECT
EmployeeName,
Salary
FROM Employees
ORDER BY Salary DESC
FETCH FIRST 5 ROWS ONLY;
FETCH FIRST can be useful in database systems that support SQL-standard row limiting.
- FETCH FIRST limits returned rows.
- It can be combined with ORDER BY.
- Syntax support depends on the database system.
- It is useful for top-N queries.
- It is an alternative to platform-specific row-limiting syntax.
What is FETCH FIRST used for?
It limits a query result to a specified number of rows in database systems that support the syntax.
Why is row-limiting syntax database-dependent?
Different database platforms implement row limiting using different keywords and syntax.