MYSQL Tutorial



MySQL LIMIT


MySQL LIMIT Clause

The LIMIT clause restricts the number of rows returned by a query. It’s super useful when you want to preview just a few records or paginate results.

Syntax

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

- number_of_rows: How many rows you want to fetch.
- OFFSET (optional): Number of rows to skip before starting to return rows.

Example 1: Fetch first 5 rows

SELECT * FROM products
LIMIT 5;
  

Returns the first 5 rows from the products table.

Example 2: Skip first 10 rows and fetch next 5

SELECT * FROM products
LIMIT 5 OFFSET 10;
  

Skips first 10 rows and returns rows 11 to 15.

Example 3: Using LIMIT with ORDER BY

SELECT * FROM employees
ORDER BY salary DESC
LIMIT 3;
  

Fetches top 3 highest-paid employees.

Quick Tips

  • You can use LIMIT without OFFSET, which defaults to 0.
  • LIMIT x, y is a shorthand for LIMIT y OFFSET x in MySQL.
  • Great for pagination by fetching chunks of rows per page.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review