Re: Fetching last n records from Posgresql

Поиск
Список
Период
Сортировка
От Sándor Daku
Тема Re: Fetching last n records from Posgresql
Дата
Msg-id CAKyoTgZvHC8DcGkw-UnN2CGknprMVUdJEe8ugZpUGqjMnQonUA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Fetching last n records from Posgresql  ("Deole, Pushkar (Pushkar)" <pdeole@avaya.com>)
Список pgsql-general
On 30 March 2016 at 11:36, Deole, Pushkar (Pushkar) <pdeole@avaya.com> wrote:

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@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Moreno Andreo
Sent: Wednesday, March 30, 2016 3:03 PM
To: pgsql-general@postgresql.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.-

Slight modification then...

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


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

В списке pgsql-general по дате отправления:

Предыдущее
От: Moreno Andreo
Дата:
Сообщение: Re: Fetching last n records from Posgresql
Следующее
От: Sridhar N Bamandlapally
Дата:
Сообщение: Re: pg_largeobject