Amrin
Amrin

Reputation: 1505

How to write rownum in where clause in PostgreSQL

I am quite new to Postgres database. I have one query:

select offer_id, offer_date
  from CMS_OFFER
 where ROWNUM < 300

which executes in Oracle but in Postgres it is not excuted. I tried with row_number() also. It is not able to execute. Please help me: how I can achieve this?

Upvotes: 1

Views: 28936

Answers (2)

Andrey Frolov
Andrey Frolov

Reputation: 1534

select offer_id,offer_date from CMS_OFFER limit 299

Upvotes: 2

Thilo
Thilo

Reputation: 262774

While not exactly the same as Oracle's ROWNUM, Postgresql has LIMIT:

select offer_id,offer_date from CMS_OFFER  LIMIT 299

The difference is that ROWNUM is applied before sorting, and LIMIT after sorting (which is usually what you want anyway).

Upvotes: 7

Related Questions