Professional Documents
Culture Documents
org/sql-fetch/
sqltutorial.org
Summary: in this tutorial, you will learn how to use the SQL
FETCH clause to limit the number of rows returned by a query.
In this syntax:
The ROW and ROWS, FIRST and NEXT are the synonyms,
We will use the employees table in the sample database for the
demonstration.
The following statement returns the first employee who has the
highest salary:
SELECT
employee_id,
first_name,
last_name,
salary
FROM employees
ORDER BY
salary DESC
OFFSET 0 ROWS
FETCH NEXT 1 ROWS ONLY;
SELECT
employee_id,
first_name,
last_name,
salary
FROM employees
ORDER BY
salary DESC
OFFSET 5 ROWS
FETCH NEXT 5 ROWS ONLY;
In this tutorial, you have learned how to use the SQL FETCH
clause to skip N rows in a result set before starting to return any
rows.
YesNo