What is the difference between the MySQL LIMIT range from 0.500 to 1.500?

If I want in rows 1 to 500 MySQL should I use LIMIT 0, 500 or LIMIT, 1, 500? What is the difference? Thank!

+3


source to share


3 answers


The first starts with the first record of the entire result, and the second starts with the second record of the result.

Consider the following entries

ID
1 -- index of the first record is zero.
2
3
4
5
6

      

if you follow



LIMIT 0, 3
-- the result will be ID: 1,2,3

LIMIT 1, 3
-- the result will be ID: 2,3,4

      

other (s)

+15


source


In MySQL, the value for LIMIT n1, n2 is:

n1: starting index
n2: number of record / data you want to show

For example:

ID
-------------------------
1 ------------> index 0
2
3
4
five
6
7
8
nine
10 ------------> index 9


Now if you write a query like

SELECT * from tbl_name LIMIT 0.5
Output: 
1
2
3
4
five

And if you write a query like

SELECT * from tbl_name LIMIT 2.7
Output: 
3
4
five
6
7
8
nine
+1


source


@JohnWoo This is not correct. The order of the lines from the operator SELECT

without a clause is ORDER BY

not specified. Therefore, while visually looking at the order of output of such a query, it might appear that it is defined in a particular order, this order is not guaranteed and therefore not reliable. If you want the result set to be ordered in a certain way, you must use a clause ORDER BY

.

0


source







All Articles