Re: Fetching last n records from Posgresql

From: "Deole, Pushkar (Pushkar)" <pdeole(at)avaya(dot)com>
To: Moreno Andreo <moreno(dot)andreo(at)evolu-s(dot)it>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Fetching last n records from Posgresql
Date: 2016-03-30 09:36:47
Message-ID: 78A4D6BFBAA5BA49A5E94DA00A6A76E309864486@AZ-FFEXMB04.global.avaya.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am sorry I didn’t clarify my requirement properly.. I want the ‘n’ oldest records, however, they should sorted with the recent record first and I want this to happen in the query itself so I don’t have to care about sorting through the application..

From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Moreno Andreo
Sent: Wednesday, March 30, 2016 3:03 PM
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Fetching last n records from Posgresql

Il 30/03/2016 11:19, Deole, Pushkar (Pushkar) ha scritto:
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)
so remove "desc", in order to have ascending ordering, thus first 5 records are the five oldest:

select * from t order by record_date limit 5

Cheers
Moreno.-

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Moreno Andreo 2016-03-30 09:42:15 Re: Fetching last n records from Posgresql
Previous Message Moreno Andreo 2016-03-30 09:33:08 Re: Fetching last n records from Posgresql