Re: Fetching last n records from Posgresql

From: Sándor Daku <daku(dot)sandor(at)gmail(dot)com>
To: "Deole, Pushkar (Pushkar)" <pdeole(at)avaya(dot)com>
Cc: John R Pierce <pierce(at)hogranch(dot)com>, "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:28:38
Message-ID: CAKyoTgb=Lx1ZkQYyjruUhDbhX2vPJMyf9OaTPp94+OHvE2S=0w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 30 March 2016 at 11:19, Deole, Pushkar (Pushkar) <pdeole(at)avaya(dot)com>
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(at)postgresql(dot)org [mailto:
> pgsql-general-owner(at)postgresql(dot)org] *On Behalf Of *John R Pierce
> *Sent:* Wednesday, March 30, 2016 12:38 PM
> *To:* pgsql-general(at)postgresql(dot)org
> *Subject:* Re: [GENERAL] 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
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Moreno Andreo 2016-03-30 09:33:08 Re: Fetching last n records from Posgresql
Previous Message Deole, Pushkar (Pushkar) 2016-03-30 09:19:55 Re: Fetching last n records from Posgresql