1. Syntax of LIMIT
SELECT column_name(s)
FROM table_name
LIMIT number_of_rows;
LIMIT number_of_rows
: Specifies the maximum number of records to fetch.Let’s assume we have a table customers
with multiple records. We want to retrieve only the first 5 customers.
SELECT * FROM customers
LIMIT 5;
In this example:
customers
table.To skip a certain number of records and fetch the next set, we use LIMIT with OFFSET.
SELECT * FROM customers
LIMIT 5 OFFSET 10;
LIMIT
controls the number of results returned.OFFSET
to skip records.The LIMIT
clause in MySQL is a powerful tool for managing query results efficiently. It helps in pagination and performance optimization by fetching only the necessary data instead of retrieving all records.