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.
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.
SELECT * FROM products LIMIT 5;
Returns the first 5 rows from the products
table.
SELECT * FROM products LIMIT 5 OFFSET 10;
Skips first 10 rows and returns rows 11 to 15.
SELECT * FROM employees ORDER BY salary DESC LIMIT 3;
Fetches top 3 highest-paid employees.
LIMIT
without OFFSET
, which defaults to 0.LIMIT x, y
is a shorthand for LIMIT y OFFSET x
in MySQL.Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!