Complete the code to limit the query to return only the first 5 rows.
SELECT * FROM employees ORDER BY employee_id [1] 5 ROWS ONLY;
The SQL standard way to limit rows is using FETCH FIRST. In PostgreSQL, LIMIT also works but here we focus on the standard syntax.
Complete the code to fetch the first 10 rows only.
SELECT name, salary FROM staff ORDER BY salary DESC [1] 10 ROWS ONLY;
FETCH FIRST is used to get the first set of rows. The ROWS ONLY clause specifies the exact number of rows to return.
Fix the error in the query to correctly fetch the next 5 rows after skipping 10 rows.
SELECT * FROM orders ORDER BY order_date [1] 10 ROWS [2] 5 ROWS ONLY;
To paginate, use OFFSET to skip rows, then FETCH NEXT to get the next set of rows.
Fill both blanks to paginate: skip 20 rows and fetch the next 10 rows.
SELECT product_id, price FROM products ORDER BY price DESC [1] 20 ROWS [2] 10 ROWS ONLY;
Use OFFSET to skip rows and FETCH NEXT to get the next rows for pagination.
Fill all three blanks to select customer names, skip 15 rows, and fetch the next 7 rows only.
SELECT [1] FROM customers ORDER BY customer_id [2] 15 ROWS [3] 7 ROWS ONLY;
Select the column customer_name, then use OFFSET to skip rows and FETCH NEXT to fetch the next rows.