开发者

SQL using count value as offset

This is a follow on from another question i made

I have this query that counts all the records up to a certain point i choose whcih works fine

SELECT count(*)FROM news WHERE id < 18

this query gives me a count of 7

I am now having problems with the offset which would be the result of th开发者_高级运维e above query

I tried using this query

SELECT * FROM `news` ORDER BY id DESC LIMIT 7,1

but i get id number 13 instead of 18

The ids i should have is 2, 7, 10, 11, 12, 13, 16, 18, 19, 20, 21, 22, 23

I have tried using order by id desc in the count query which does give a different result but still wrong id displayed


I dont see a problem here: You order the result by id DESC which means your result is ordered by other way around and 8th value(0..7) is 13.

Try sorting it by ASC then it will give you 18

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜