0

well this should be easy for someone---

I am trying to select specific rows in a database

SELECT * FROM customers LIMIT 10,20

but it always returns 20 rows

what is going on, and why does the minimum not have any value?

5
  • SELECT * FROM customer LIMIT 19,20 --- this returns 14 rows Commented Mar 28, 2013 at 23:43
  • That means you have 33 customers? Commented Mar 28, 2013 at 23:44
  • dev.mysql.com/doc/refman/5.0/en/select.html Commented Mar 28, 2013 at 23:44
  • Before going to stackoverflow and asking a question at least consult the documentation please. dev.mysql.com/doc/refman/5.0/en/select.html Commented Mar 28, 2013 at 23:45
  • thanks Daniel for the help? I get theres documentation - it wasn't clear to me and I needed some help, others helped me out and I was able to solve the issue - you have zero value here Commented Mar 28, 2013 at 23:49

4 Answers 4

6
LIMIT X, Y

means that you get Y results starting from number X+1.

So if you want values from 11 to 20 you need to use:

LIMIT 10, 10
Sign up to request clarification or add additional context in comments.

3 Comments

and it is shown that I have been coding for 15 hours... I read the doc 10 times, and looked at their demo but couldn't get it.... Thanks! Will accept after time limit
Specifically X is the number of rows to skip and Y is the number of rows to return after skipping X rows.
Thanks @DanielWilliams you are right. I update my answer with this specification.
1

You would want to do limit 10 or lmit 0, 10 for 10 results

Comments

1

The second number of the LIMIT clause is the number of rows to be returned, not the last index. if you only want 10 rows, replace 20 by 10 in your query limit clause.

SELECT * 
FROM customers
LIMIT 10, 10

Comments

1

Limit with two arguments (x,y) means you get rows from x+1 to y. From the MySQL Manual:

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants (except when using prepared statements).

With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):

SELECT * FROM tbl LIMIT 5,10;

Retrieve rows 6-15 To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter.

This statement retrieves all rows from the 96th row to the last:

SELECT * FROM tbl LIMIT 95,18446744073709551615;

With one argument, the value specifies the number of rows to return from the beginning of the result set:

SELECT * FROM tbl LIMIT 5;

Retrieve first 5 rows In other words, LIMIT row_count is equivalent to LIMIT 0, row_count.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.