SQL

LIMIT and OFFSET

Learn how to restrict the number of rows returned by a query.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Learn how to restrict the number of rows returned by a query. This hands-on tutorial focuses on practical implementation of limit and offset concepts.

Limiting Results

The LIMIT clause is used to specify the number of records to return. This is useful on large tables to improve performance or when you only need a sample of data.

[!NOTE] Different databases use different syntax for limiting rows. MySQL, PostgreSQL, and SQLite use LIMIT. SQL Server uses TOP. Oracle uses FETCH FIRST. We will use the standard LIMIT syntax here (supported by our playground).

Syntax

SELECT column_names
FROM table_name
LIMIT number;

Example: Top 3 Products

Get the first 3 products from the table.

SQL PLAYGROUND
⏳ Loading editor…

Pagination with OFFSET

The OFFSET clause allows you to skip a specific number of rows before returning the result. This is commonly used for pagination (e.g., "Show results 11-20").

Syntax

SELECT column_names
FROM table_name
LIMIT number OFFSET number;

Example: Skip First 2, Take Next 3

SQL PLAYGROUND
⏳ Loading editor…

This query skips the first 2 customers and returns the next 3 (customers 3, 4, and 5).