Maxim Consulting

View Original

Oracle Tip - FETCH FIRST

Until Oracle 12c, Oracle’s approximation of the TOP option of SELECT in SQL Server was a poor variant using ROWNUMBER.

FETCH FIRST is a lesser known option that better provides the equivalent functionality of a TOP command allowing ORDER BY natively.

SELECT * FROM EMPLOYEES ORDER BY EMP_ID FETCH FIRST 10 ROWS ONLY
There's no BOTTOM feature, but that can be done easily by sliding in a DESC after the ORDER BY.