Reputation: 193
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...
Upvotes: 1
Views: 60
Reputation: 2101
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:
offset
(5) specifies the offset of the first row to return. The
offset
of the first row is 0, not 1.count
(10) specifies maximum number of rows to return.Upvotes: 0
Reputation: 111
As you need only 5 rows and you need to skip the first 5 rows use: LIMIT(5,5)
Upvotes: 0
Reputation: 125620
In mySQL LIMIT X, Y
means
X
is starting element (offset) Y
is number of elements that you want to be returnedthat'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
.
Upvotes: 2