开发者

Get the Nth row in Postgresql

In MySQL I can do SELEC开发者_如何学JAVAT * FROM tbl LIMIT 10

In MSSQL I can do SELECT TOP 5 * FROM tbl

How do I do this in Postgresql?


See the LIMIT clause:

SELECT * FROM tbl LIMIT 10

or

SELECT * FROM tbl OFFSET 20

and, of course

SELECT * FROM tbl LIMIT 10 OFFSET 10


From the PostgreSQL docs:

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.

See docs for LIMIT and OFFSET

I hope this helps.


The syntax you quote for MySQL should work just fine for Postgresql as well. Doesn't it?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜