数据库分页查询
mysql分页查询:
数据库表记录为:
[img]http://dl2.iteye.com/upload/attachment/0085/9300/8204b147-6c42-3d71-8b6d-8a75f9a5bd77.jpg[/img]
SELECT * FROM students ORDER BY ID LIMIT 30,10;
查询结果如下:
[img]http://dl2.iteye.com/upload/attachment/0085/9302/7c35da94-5c4e-379a-8052-7e81301d3171.jpg[/img]
SQL Server分页查询:
数据库表记录:
[img]http://dl2.iteye.com/upload/attachment/0085/9304/d93326a7-7ab6-331f-bc48-a4ca3f0b0f80.jpg[/img]
查询方法一:
SELECT top 10 * FROM test.dbo.t_users WHERE ID NOT IN (SELECT top 30 ID FROM test.dbo.t_users ORDER BY ID) ORDER BY ID;
运行结果:
[img]http://dl2.iteye.com/upload/attachment/0085/9306/68719771-7c33-3cbd-a475-ec2fab32eb6e.jpg[/img]
查询方法2:
SELECT top 10 * FROM test.dbo.t_users WHERE ID IN (SELECT top 40 ID FROM test.dbo.t_users ORDER BY ID) ORDER BY ID DESC;
运行结果:
[img]http://dl2.iteye.com/upload/attachment/0085/9308/85c1f7ea-5f86-36fb-bd52-9ead78c38b38.jpg[/img]