mysql - How can I write a SELECT query with starting row of particular PK? -
i'm using mysql, support offset , limit, it's great. if want query first row equal particular primary key instead of page index?
e.g. have table:
id name height 1 kevin 1.67 2 bob 1.82 3 jane 1.70 4 wayne 1.59
i want list of people order height asc first page's last id 1, whole view 4 1 3 2 (page size = 2)
something should like:
select id,name,height table offset ???? limit 2 order height asc
so should get:
3 jane 1.70 2 bob 1.82
try this
logic :
page_size page_number offset 2 1 (2*1)-1 = 1 2 2 (2*2)-1 = 3 2 3 (2*3)-1 = 5
query :
select id,name,height table order height asc, id asc limit 2 offset (page_size * page_number)-1
Comments
Post a Comment