您的位置:首页 > 数据库

postgresql 使用limit分页

2012-08-10 11:21 337 查看
SELECT select_list
FROM table_expression
[ ORDER BY ... ]
[ LIMIT { number | ALL } ] [ OFFSET number ]
举例:
select * from userinfo limit 10 offset 3 选出的是4-13条记录。没有经过orderby,多次执行语句可能结果不同;经过orderby则结果相同。
If a limit count is given, no more than that many rows will be returned.
返回不多于limit的条数
OFFSET says to skip that many rows before beginning to return rows.
跳过前offset条数
If both OFFSET and LIMIT appear, then OFFSET rows are skipped before starting to count the LIMIT rows that are returned.
二者一起用时offset跳过后开始数limit
using different LIMIT/OFFSET values to select different subsets of a query result will give inconsistent results unless you enforce a predictable result ordering with ORDER BY. This is not a bug; it is an inherent consequence of the fact that SQL does not promise to deliver the results of a query in any particular order unless ORDER BY is used to constrain the order.
只用offset和limit会导致多次查询结果不同,用orderby可以避免,但是这不是bug

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: