Re: How to obtain the maximum value of a date, between 3 tables...

From: "Igor Neyman" <ineyman(at)perceptron(dot)com>
To: "Andre Lopes" <lopes80andre(at)gmail(dot)com>, "postgresql Forums" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to obtain the maximum value of a date, between 3 tables...
Date: 2010-12-08 19:19:26
Message-ID: F4C27E77F7A33E4CA98C19A9DC6722A206E06497@EXCHANGE.corp.perceptron.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Original Message-----
> From: Andre Lopes [mailto:lopes80andre(at)gmail(dot)com]
> Sent: Wednesday, December 08, 2010 8:16 AM
> To: postgresql Forums
> Subject: How to obtain the maximum value of a date, between 3
> tables...
>
> Hi,
>
> I need to obtain the maximum value of a date, but that
> comparison will be made between 3 tables... I will explain
> better with a query...
>
> [code]
> select
> a.last_refresh_date as d1, ae.last_refresh_date as d2,
> ha.last_refresh_date as d3 from tbl1 a join tbl2 ae on
> a.id_anuncio_externo = ae.id_anuncio_externo join tbl3 ha on
> a.id_anuncio_externo = ha.id_anuncio_externo [/code]
>
> My question is how is the best way to obtain with date is the
> greatest, d1, d2 or d3
>
> Can you guys give me a clue.
>
> Best Regards,
>
>
>

This:

SELECT GREATEST(q.d1, q.d2, q.d3) FROM
(select
a.last_refresh_date as d1, ae.last_refresh_date as d2,
ha.last_refresh_date as d3 from tbl1 a join tbl2 ae on
a.id_anuncio_externo = ae.id_anuncio_externo join tbl3 ha on
a.id_anuncio_externo = ha.id_anuncio_externo) q;

should do it.

Igor Neyman

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gabi Julien 2010-12-08 20:15:32 Re: Postgresql 9.1 pg_last_xact_replay_timestamp limitations
Previous Message James B. Byrne 2010-12-08 18:40:29 Set new owner on cloned database