Mysql – Two-sided LIMIT in MySQL

MySQL

I have a table with 4 rows of data always in the same order. What I want to do is to limit the query to just get the 2th to 3th row.

for example a table 'food' with:

cake
pizza
chocolate
lettuce

SELECT * from food (what do i put here to only get the rows pizza and chocolate)

This should also work for getting for example the 4th to 8th row in a table with 10 rows.

Best Answer

The LIMIT clause intended to do what you need:

SELECT * 
  FROM food 
 LIMIT 1,2  -- offset, count
;

Refer to the SELECT syntax manual for details: https://dev.mysql.com/doc/refman/8.0/en/select.html