获取 Postgresql 中的第 N 行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2082835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get the Nth row in Postgresql
提问by Byron Whitlock
In MySQL I can do SELECT * FROM tbl LIMIT 10
在 MySQL 我可以做 SELECT * FROM tbl LIMIT 10
In MSSQL I can do SELECT TOP 5 * FROM tbl
在 MSSQL 我可以做 SELECT TOP 5 * FROM tbl
How do I do this in Postgresql?
我如何在 Postgresql 中做到这一点?
回答by Dirk
See the LIMIT
clause:
见LIMIT
条款:
SELECT * FROM tbl LIMIT 10
or
或者
SELECT * FROM tbl OFFSET 20
and, of course
而且当然
SELECT * FROM tbl LIMIT 10 OFFSET 10
回答by Bob Jarvis - Reinstate Monica
From the PostgreSQL docs:
来自 PostgreSQL 文档:
SELECT select_list
FROM table_expression
[ ORDER BY ... ]
[ LIMIT { number | ALL } ] [ OFFSET number ]
So LIMIT should work as it does in MySQL. OFFSET is used to skip rows before starting to return data.
所以 LIMIT 应该像在 MySQL 中一样工作。OFFSET 用于在开始返回数据之前跳过行。
I hope this helps.
我希望这有帮助。
回答by Jakob Borg
The syntax you quote for MySQL should work just fine for Postgresql as well. Doesn't it?
您为 MySQL 引用的语法也适用于 Postgresql。不是吗?