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

Поиск
Список
Период
Сортировка
От Andre Lopes
Тема Re: How to obtain the maximum value of a date, between 3 tables...
Дата
Msg-id AANLkTim3hT-hC-3dCNSgZaOsp7Q8DjaF3mLir=dvjuqM@mail.gmail.com
обсуждение исходный текст
Ответ на Re: How to obtain the maximum value of a date, between 3 tables...  (Jon Nelson <jnelson+pgsql@jamponi.net>)
Ответы Re: How to obtain the maximum value of a date, between 3 tables...  (Vincent Veyron <vv.lists@wanadoo.fr>)
Список pgsql-general
Hi,

Thanks for the reply.

And there are other options to do it without using a UNION? I don't need to know from witch table comes the greatest date, but the query is complex, this query is part of an UNION. The use of the CASE WHEN could be an alternative?

Best Regards,




On Wed, Dec 8, 2010 at 1:20 PM, Jon Nelson <jnelson+pgsql@jamponi.net> wrote:
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 по дате отправления:

Предыдущее
От: c k
Дата:
Сообщение: Asynchronous query execution
Следующее
От: John R Pierce
Дата:
Сообщение: Re: Asynchronous query execution