SQL LIMIT and OFFSET

LIMIT caps how many rows a query returns. Combined with ORDER BY, it answers “top N” questions like the three most expensive drinks. OFFSET skips rows, which is how pagination works.

Updated December 1, 2026

Syntax

SELECT columns
FROM table_name
ORDER BY column
LIMIT row_count OFFSET rows_to_skip;

Return the first few rows

A quick LIMIT keeps exploration fast on big tables. Without ORDER BY, though, the database may return any rows it likes.

SELECT *
FROM drinks
LIMIT 3;
Result on the SQL Café sample data (3 rows)
idnamecategorypricecaloriescaffeinated
1Espressocoffee351
2Lattecoffee4.51901
3Cappuccinocoffee4.251201

Top N with ORDER BY

Sort first, then limit. This returns the three most expensive drinks.

SELECT name, price
FROM drinks
ORDER BY price DESC
LIMIT 3;
Result on the SQL Café sample data (3 rows)
nameprice
Matcha Latte5.25
Mocha5
Cold Brew4.75

Page through results with OFFSET

OFFSET skips rows before LIMIT starts counting. With 3 rows per page, page 2 is LIMIT 3 OFFSET 3.

SELECT id, name
FROM drinks
ORDER BY id
LIMIT 3 OFFSET 3;
Result on the SQL Café sample data (3 rows)
idname
4Mocha
5Cold Brew
6Matcha Latte

Common mistakes

Practice LIMIT and OFFSET interactively

Write real queries in your browser and get instant feedback in the lesson “SELECT * and LIMIT” (Unit 1). It’s free.

Frequently asked questions

What is the SQL Server version of LIMIT?

SQL Server uses SELECT TOP 3 ... or OFFSET 0 ROWS FETCH NEXT 3 ROWS ONLY. Oracle and the SQL standard use FETCH FIRST 3 ROWS ONLY. PostgreSQL, MySQL and SQLite support LIMIT.

How do I get the second-highest value?

Sort descending and skip one row: ORDER BY price DESC LIMIT 1 OFFSET 1. If values can tie, use DISTINCT or DENSE_RANK instead.

Related SQL tutorials