开发者

Need a SQL select statement for pagination

I have a MySQL table with columns id, name and active. I need to write a SQL select statement that will return a subset of the id's from this table starting at a specific row number, returning the next 20 rows inclusive. For example:

id   name   active
------------------
a开发者_C百科    One    true
b    Two    true
c    Three  true
d    Four   false
e    Five   true
f    Six    false

I need to be able to say start at row 3 in the table and return the id's for the next 3 rows inclusive (c, d and e).

Thanks in advance!


Use LIMIT:

SELECT 
  *
FROM 
  MyTable
Limit 2,3


Generally, the syntax is:

SELECT ... LIMIT <start>, <length>

So in your case:

SELECT ... LIMIT 2, 3
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜