User Tools

Site Tools


rowlimitingclause

Row Limiting Clause

Display the highest 5 salaries

SELECT id, description, salary
  FROM employees
ORDER BY salary DESC
FETCH FIRST 5 ROWS ONLY;

Display the 6th to the 10th highest salaries

SELECT id, description, salary
  FROM employees
ORDER BY salary DESC
OFFSET 5 ROWS FETCH NEXT 5 ROWS ONLY;

Can also use NEXT 20 PERCENT ROWS in place of NEXT 5 ROWS.
Can place WITH TIES at the end. This can mean you will get more than the number of rows you specified.

rowlimitingclause.txt · Last modified: 2021/12/06 11:30 by 127.0.0.1