Search Postgresql Archives

Re: Fetching last n records from Posgresql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 30 March 2016 at 11:19, Deole, Pushkar (Pushkar) <pdeole@xxxxxxxxx> wrote:

select * from t order by record_date desc limit 5;

 

this will return the recent 5 records.. what I want is the oldest 5 records (in last 30 days)

 

From: pgsql-general-owner@xxxxxxxxxxxxxx [mailto:pgsql-general-owner@xxxxxxxxxxxxxx] On Behalf Of John R Pierce
Sent: Wednesday, March 30, 2016 12:38 PM
To: pgsql-general@xxxxxxxxxxxxxx
Subject: Re: Fetching last n records from Posgresql

 

On 3/29/2016 11:40 PM, Deole, Pushkar (Pushkar) wrote:

 

WITH t AS (

    SELECT * FROM mytable ORDER BY record_date ASC LIMIT 5

)

SELECT * FROM t ORDER BY record_date DESC;

 


why do it twice when you can just do....



    select * from t order by record_date desc limit 5;
-- 

john r pierce, recycling bits in santa cruz
Then:

select * from t where record_date>now()-'30 day'::interval order by record_date limit 5;

Regards,
Sándor



Ezt az e-mailt egy Avast védelemmel rendelkező, vírusmentes számítógépről küldték.
www.avast.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux