From: | Dennis Gearon <gearond(at)cvc(dot)net> |
---|---|
To: | "Jay O'Connor" <joconnor(at)cybermesa(dot)com> |
Cc: | Mark Tessier <m_tessier(at)sympatico(dot)ca>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Selecting the most recent date |
Date: | 2003-04-28 18:24:40 |
Message-ID: | 3EAD71E8.4090807@cvc.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
that assumes all dates are older than today, which they man not be. What if it's for an appointment system?
Jay O'Connor wrote:
> On 2003.04.28 10:26 Mark Tessier wrote:
>
>>Hi,
>>
>>My question is hopefully a simple one: If I have several rows, each
>>containing a date field, and I want to select the row that has the date
>>closest to today's date, what would be the syntax for carrying that out.
>
>
>
> Unless I misunderstand, it should be just a matter of an ORDER BY clause in
> reverse order with a LIMIT BY clause to limit yuorself to the highest
> result
>
> SELECT * from myyable ORDER BY datefield DESC LIMIT 1;
>
> DESC means to using a descending sorta order (versus "ASC")
> LIMIT 1 means how many rows you want returned
>
> Take care,
> Jay
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>
From | Date | Subject | |
---|---|---|---|
Next Message | Pablo Dall'Oglio | 2003-04-28 18:43:06 | database reporting tool under GPL |
Previous Message | Dennis Gearon | 2003-04-28 18:23:38 | Re: Setting a field to default if blank value |