Search code examples
mysqllimit

LIMIT condition not working as expected


SELECTing rows with LIMIT condition delivers unexpected number of rows:

SELECT `id`, `Date`, `row1`, `row2`, `row3`, `row4`, `row5` 
FROM `table` 
ORDER BY `id` ASC, `Date` ASC 
LIMIT 1, 800

This SELECT shows exactly what it should: 800 rows

SELECT `id`, `Date`, `row1`, `row2`, `row3`, `row4`, `row5` 
FROM `table` 
ORDER BY `id` ASC, `Date` ASC 
LIMIT 801, 1600

This SELECT does not deliver what it should: delivering 1600 rows instead of 800.

Why is LIMIT condition not working properly?


Solution

  • LIMIT and Offset are not from and to values. Offset is the number of documents/rows to skip and limit is the maximum number of rows to be shown. In your case, to skip 800 rows and show next 800 records, it should be LIMIT 800,800