If I want in MySQL rows 1 through 500, should I use LIMIT 0, 500 or LIMIT, 1, 500? What is the difference? Thanks!
In MySQL the LIMIT clause is used with the SELECT statement to restrict the number of rows in the result set.
The answer, in short, is yes.If you limit your result to 1, then even if you are "expecting" one result, the query will be faster because your database wont look through all your records. It will simply stop once it finds a record that matches your query.
Limit Data Selections From a MySQL Database Assume we wish to select all records from 1 - 30 (inclusive) from a table called "Orders". The SQL query would then look like this: $sql = "SELECT * FROM Orders LIMIT 30"; When the SQL query above is run, it will return the first 30 records.
This LIMIT clause would return 3 records in the result set with an offset of 1. What this means is that the SELECT statement would skip the first record that would normally be returned and instead return the second, third, and fourth records.
The first one starts from the first record of the whole result, while the second one starts on the second record of the result.
Consider the following records
ID
1 -- index of the first record is zero.
2
3
4
5
6
if you execute
LIMIT 0, 3
-- the result will be ID: 1,2,3
LIMIT 1, 3
-- the result will be ID: 2,3,4
OTHER(s)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With