How to use LIMIT for pagination in MySQL?

In MySQL, the LIMIT keyword can be used to achieve pagination for queries. The syntax for LIMIT is as follows:

SELECT column1, column2, ...
FROM table
LIMIT offset, count;

The offset parameter indicates the starting position of the result set, while the count parameter indicates the number of rows to be returned.

For example, to retrieve the first 5 records from the table, you can use the following statement:

SELECT * FROM table
LIMIT 0, 5;

To query records 6 through 10 of the result set, you can use the following statement:

SELECT * FROM table
LIMIT 5, 5;

This allows for pagination in MySQL using the LIMIT clause.

广告
Closing in 10 seconds
bannerAds