Re: How to obtain the maximum value of a date, between 3 tables... - Mailing list pgsql-general

From Jon Nelson
Subject Re: How to obtain the maximum value of a date, between 3 tables...
Date
Msg-id AANLkTin-sa2hpE5-qiJL1WbvaVZVY+KokfdM9tdNFZCd@mail.gmail.com
Whole thread Raw
In response to How to obtain the maximum value of a date, between 3 tables...  (Andre Lopes <lopes80andre@gmail.com>)
Responses Re: How to obtain the maximum value of a date, between 3 tables...  (Andre Lopes <lopes80andre@gmail.com>)
List pgsql-general
On Wed, Dec 8, 2010 at 7:15 AM, Andre Lopes <lopes80andre@gmail.com> wrote:
> 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

If you don't need to know which table it came from I would probably try
select a.last_refresh_date as d1, NULL as d2, NULL as d3 FROM tbl1 as a
UNION ALL
...


--
Jon

pgsql-general by date:

Previous
From: "Massa, Harald Armin"
Date:
Subject: Re: Using PG with Windows EFS or TrueCrypt for encryption
Next
From: Dmitriy Igrishin
Date:
Subject: Re: OID of type by name.