Back to Yugabyte Db

FETCH

community/learn/content/01-SQL-Basics/02-fundamentals/06-fetch.md

2026.1.0.0-b29823 B
Original Source

SELECT with FETCH and ORDER BY clauses

In this exercise we'll query the customers table and order the results by company_name in ascending order, while limiting the rows returned to 7.

SELECT customer_id,
       company_name,
       contact_name,
       contact_title
FROM customers
ORDER BY company_name ASC FETCH NEXT 7 ROWS ONLY;

This query should return 7 rows.

SELECT with FETCH, OFFSET and ORDER BY clauses

In this exercise we'll query the customers table and order the results by company_name in ascending order, while limiting the rows returned to the 7 that come after the first 2.

SELECT customer_id,
       company_name,
       contact_name,
       contact_title
FROM customers
ORDER BY company_name ASC
OFFSET 2 FETCH NEXT 7 ROWS ONLY;

This query should return 7 rows.