1

I do that query that should return me 5 query but I get 10...

SELECT *
FROM article ar, account ac
WHERE ar.approved = '1'
AND ar.author = ac.id
ORDER BY ar.id DESC
LIMIT 5 , 10

Showing rows 0 - 9 (10 total, Query took 0.0028 sec)

What am I doing wrong? It was working fine before...

2
  • You are asking for 10 rows. If you want 5 rows, use LIMIT 5, 5,. Commented Dec 1, 2014 at 4:07
  • Mention what is the output? Commented Dec 1, 2014 at 4:07

3 Answers 3

2

In mySQL LIMIT X, Y means

  • X is starting element (offset)
  • Y is number of elements that you want to be returned

that's why you're getting 10 rows back.

If you only want 5 rows back and you need 5 first rows to be skipped, you should use LIMIT 5, 5.

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

1 Comment

Thanks that was the issue. I tough it was working another way. I will accept it as answer in 10 min.
0

As you need only 5 rows and you need to skip the first 5 rows use: LIMIT(5,5)

Comments

0

Try this:

SELECT *
FROM article ar, account ac
WHERE ar.approved = '1'
AND ar.author = ac.id
LIMIT 5, 10
ORDER BY ar.id DESC

Here is the grammer:

  1. The offset(5) specifies the offset of the first row to return. The offset of the first row is 0, not 1.
  2. The count(10) specifies maximum number of rows to return.

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.