tags:

views:

202

answers:

3

In MySQL I can do SELECT * FROM tbl LIMIT 10

In MSSQL I can do SELECT TOP 5 * FROM tbl

How do I do this in Postgresql?

+4  A: 

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

calmh
+6  A: 

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
Dirk
+4  A: 

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.

Bob Jarvis