Skip to content

SQL LIMIT Clause

Syntax

The LIMIT clause in SQL is used to specify the maximum number of rows to return in the result set.

-- Retrieve a specific number of rows
SELECT column1, column2
FROM table_name
LIMIT number_of_rows;
-- Retrieve rows with an offset
SELECT column1, column2
FROM table_name
LIMIT offset, number_of_rows;

Example

-- Retrieve the first 2 rows
SELECT name, department
FROM employees
LIMIT 2;
/* Output:
| name | department |
|------------|------------|
| John Doe | Sales |
| Jane Smith | Marketing |
*/
-- Retrieve 2 rows starting from the second row
SELECT name, department
FROM employees
LIMIT 1, 2;
/* Output:
| name | department |
|-------------|------------|
| Jane Smith | Marketing |
| Alice Brown | HR |
*/