Beginner

397. FETCH FIRST

Learn how FETCH FIRST can be used to restrict query results in SQL-standard style syntax.

📘 Lesson 397 of 728 ⏱ 9 min 🎯 Intermediate

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.

SQL
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.

Have you finished this lesson?

Introduction to SQL – All Lessons