LIMIT OFFSET in SQL

Level 376 keystrokes

OFFSET skips a specified number of rows before returning results.

SQL code

-- Return the id, name and price of products
1SELECT
2 id,
3 name,
4 price
5FROM
6 products
-- Sort from the most expensive to the cheapest
7ORDER BY
8 price DESC
-- OFFSET 20 skips the first 20 rows, then LIMIT 10 returns up to 10 rows
-- This is page 3 with 10 items per page (rows 21-30); here only 3 rows remain
9LIMIT
10 10 OFFSET 20;

Output

+----+---------+-------+
| id | name    | price |
+----+---------+-------+
| 21 | Laptop  | 899.0 |
| 22 | Tablet  | 599.0 |
| 23 | Monitor | 399.0 |
+----+---------+-------+
3 rows in set
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this SQL code and how often they appear.

  • ,× 2
  • ;× 1

More SQL examples at level 3

← SQL typing practice