What is the usage of OFFSET in MySQL?

In MySQL, OFFSET is used to specify at which row to start returning data from the query result. It is commonly used in conjunction with LIMIT to implement pagination.

The syntax for OFFSET is as follows:
SELECT * FROM table_name
LIMIT the number of rows to be returned
OFFSET the starting row number to be returned

For example, if there is a table named “customers” with 100 customer records, to return 10 records starting from the 11th row, you can use the following query:
SELECT * FROM customers
LIMIT 10
OFFSET 10

This will return records 11 to 20.

It is important to note that the OFFSET value must be a non-negative integer, and the order of LIMIT and OFFSET cannot be reversed.

bannerAds