Re: date problem

From: Richard Huxton <dev(at)archonet(dot)com>
To: tony <tony(at)tgds(dot)net>
Cc: postgres list <pgsql-general(at)postgresql(dot)org>
Subject: Re: date problem
Date: 2005-05-16 08:44:22
Message-ID: 42885D66.5060907@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

tony wrote:
> Hi,
>
> I thought this would be a classic sort of query but google did no give
> me the answer.
>
> I am attempting to select records where one of the dates is the latest
> date before today
>
> select max(date) from expo where date < now()
>
> works for one record but other fields I need must be in aggregate or
> grouped. Is there a simple SQL request to get the most recent records
> from a set of joined tables?

SELECT * FROM expo WHERE date = (SELECT max(date) FROM expo WHERE date <
now());

In fact, you might want to rewrite the subselect. Oh, and "date" is
likely to cause trouble as a column-name.

SELECT * FROM expo
WHERE my_date = (
SELECT my_date FROM expo
WHERE my_date < now()
ORDER BY my_date DESC LIMIT 1
)

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message tony 2005-05-16 08:48:20 Re: date problem
Previous Message Margus Roo 2005-05-16 08:43:09 is in postgres solution