Re: Fetching last n records from Posgresql - Mailing list pgsql-general
From | Moreno Andreo |
---|---|
Subject | Re: Fetching last n records from Posgresql |
Date | |
Msg-id | 56FB9F77.4010106@evolu-s.it Whole thread Raw |
In response to | Re: Fetching last n records from Posgresql ("Deole, Pushkar (Pushkar)" <pdeole@avaya.com>) |
List | pgsql-general |
Il 30/03/2016 11:36, Deole, Pushkar (Pushkar) ha scritto: <blockquote cite="mid:78A4D6BFBAA5BA49A5E94DA00A6A76E309864486@AZ-FFEXMB04.global.avaya.com" type="cite"> <meta name="Generator" content="Microsoft Word 14 (filtered medium)"> <!-- /* Font Definitions */ @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} @font-face {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4;} @font-face {font-family:Consolas; panose-1:2 11 6 9 2 2 4 3 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman","serif"; color:black;} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {mso-style-priority:99; color:purple; text-decoration:underline;} pre {mso-style-priority:99; mso-style-link:"HTML Preformatted Char"; margin:0in; margin-bottom:.0001pt; font-size:10.0pt; font-family:"Courier New"; color:black;} span.HTMLPreformattedChar {mso-style-name:"HTML Preformatted Char"; mso-style-priority:99; mso-style-link:"HTML Preformatted"; font-family:Consolas; color:black;} span.EmailStyle19 {mso-style-type:personal; font-family:"Calibri","sans-serif"; color:#1F497D;} span.EmailStyle20 {mso-style-type:personal-reply; font-family:"Calibri","sans-serif"; color:#1F497D;} .MsoChpDefault {mso-style-type:export-only; font-size:10.0pt;} @page WordSection1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in;} div.WordSection1 {page:WordSection1;} --> <span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">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.. <span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> <div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in"> <span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext">From:<span style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext"> 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.- select * from (select * from t where record_date >=current_date() - '30 days' order by record_date limit 5) order by record_date desc Not tested, but should work... Cheers Moreno.-
pgsql-general by date: