Available Tables

Next →

Limiting and Offsetting Results

Sometimes, you don’t need all the rows from a query — just the top few. SQL provides LIMIT and OFFSET to control how many rows are returned and where to start.

Using LIMIT

LIMIT restricts the number of rows returned. For example:

SELECT * FROM students LIMIT 5;

This returns only the first 5 rows from the students table.

Using OFFSET

OFFSET tells SQL to skip a certain number of rows before starting to return results. For example:

SELECT * FROM students LIMIT 5 OFFSET 3;

This skips the first 3 rows, then returns the next 5.

LIMIT and OFFSET are often used for pagination, where you show part of a large result set one page at a time.