| From: | Majid Azimi <majid(dot)merkava(at)gmail(dot)com> | 
|---|---|
| To: | pgsql-novice(at)postgresql(dot)org | 
| Subject: | Re: Selecting the last 2 rows of a table | 
| Date: | 2010-11-09 09:48:42 | 
| Message-ID: | 1289296122.3893.1.camel@localhost.localdomain | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-novice | 
On Tue, 2010-11-09 at 11:34 +0200, Machiel Richards wrote:
> Good day all
> 
>      I am trying to find out how I can select the last 2 or (n
> amount ) of rows from a specific table.
> 
>       We have a table which has been growing rediculously the last
> view days (I must say after a code go-live).
> 
>        I am trying to find out what data is being written to the table
> that is causing this, however due to the size of the table at the
> moment, it can cause problems so I am just interested in the last
> number of records.
> 
> 
>       I would appreciate any assistance in this.
> 
> 
> Regards
> Machiel
Or if you don't want to use "order by" you can use this but it is
inefficient:
SELECT * FROM <Table name> OFFSET (SELECT count(*) - 2 FROM <table
name>);
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Frank Bax | 2010-11-09 12:05:17 | Re: Selecting the last 2 rows of a table | 
| Previous Message | Thom Brown | 2010-11-09 09:42:22 | Re: Selecting the last 2 rows of a table |