Re: get certain # of recs - Mailing list pgsql-general

From Ian Barwick
Subject Re: get certain # of recs
Date
Msg-id 9nsmg6$1bip$1@news.tht.net
Whole thread Raw
Responses Re: get certain # of recs
List pgsql-general
Mike S. Nowostawsky wrote:

> How can one select only a certain number of records in Postgres?
>
> In other SQL langs we can use, say, for the first 20 recs:
>
> select  * from tablename where rownum < 21;
>
> WHAT should 'rownum' be to make this select work... OR is there a diff
> syntax?

use the LIMIT clause, e.g.

SELECT * FROM tablename LIMIT 20

for the first 20 rows, or

SELECT * FROM tablename LIMIT 10,20

for 10 rows beginning from the 20th row (or possibly the other way round,
the caffeine isn't working yet ;-)

When using LIMIT it is generally advisable to also use ORDER BY in order to
guarantee consistent result sets over repeated queries.

HTH

Ian Barwick


--
Ian Barwick - Developer
http://www.akademie.de

Remove SUNGLASSES to reply ;-)

pgsql-general by date:

Previous
From: "Corn"
Date:
Subject: What function in pgsql just like M$SQL @@identity?
Next
From: rdacker@pacbell.net (rdack)
Date:
Subject: Re: osx install problem