LIMIT — Limit the Number of Rows Returned

The LIMIT clause allows you to control how many rows your SQL query returns.
It is very useful when you want to:

  • Preview just a few rows
  • Display only the top results
  • Build pagination features

Syntax

SELECT column1, column2, ... FROM table_name
LIMIT number_of_rows;

Example 1: Return only the first 5 employees

SELECT name, age FROM employees
LIMIT 5;

This returns only the first 5 rows from the result set.


Example 2: Combine with ORDER BY (Top N pattern)

SELECT name, age FROM employees
ORDER BY age DESC
LIMIT 3;

This returns the 3 oldest employees — first sorting by age in descending order, then limiting to 3 rows.


Tip

  • Without ORDER BY, LIMIT just returns any N rows — the order is not guaranteed.
  • With ORDER BY, LIMIT becomes very powerful for things like "top N" queries.

The LIMIT clause is a simple but essential tool to control how much data you want to see!