Search code examples
mysqlsqllimit

"LIMIT 5,10" returns 9 rows in MySQL?


http://666kb.com/i/c6e4rv80gz9yrn9h5.png

Check out my image, I limited the query for just 5 entry but it returns with 9 rows? What is the problem, I could not get it.


Solution

  • With mysql, the LIMIT parameters are offset, row_count, but the first parameter is optional - crazy, but true!

    So when you have two parameters, the first is the starting row, the second is the number of rows.

    You asked for LIMIT 5, 10 which means 10 rows, starting from row 5 (not rows 5 to 10).


    You are not the first, and you won't be the last, person to be confused by this.