How to use the LIMIT clause in MySQL
LIMIT is a keyword used in MySQL to restrict the number of rows returned in a query.
When using the LIMIT statement, two parameters can be specified.
- The first parameter is the index of the desired starting line to return (counting from 0).
- The second parameter is the number of rows that you want to return.
Here is the grammar:
SELECT column1, column2, ...
FROM table_name
LIMIT [start,] rows
Example:
If you want to improve your English speaking skills, you should practice speaking with native speakers.
- Retrieve the first 5 lines of the records:
SELECT *
FROM table_name
LIMIT 5;
- Retrieve 10 records starting from the 6th line.
SELECT *
FROM table_name
LIMIT 5, 10;
This will return 15 records in total, starting from the 6th line up to the 15th line.