Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql

mysql

limit

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.

like image 816
Slavez Avatar asked Aug 15 '12 01:08

Slavez


2 Answers

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.

like image 151
Bohemian Avatar answered Oct 07 '22 22:10

Bohemian


In MySQL Limit function Syntax are:

SELECT column_name(s)
FROM table_name
LIMIT Rows start , Quantity of Rows for display;

Example:

SELECT *
FROM customer
LIMIT 2 , 10;
like image 45
ball Avatar answered Oct 08 '22 00:10

ball