Re: NEWBIE: How do I get the oldest date contained in 3 tables

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: NEWBIE: How do I get the oldest date contained in 3 tables
Дата
Msg-id b42b73150704091420h192d57fk419025930cf9631b@mail.gmail.com
обсуждение исходный текст
Ответ на Re: NEWBIE: How do I get the oldest date contained in 3 tables  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On 4/9/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Dann Corbit" <DCorbit@connx.com> writes:
> >> owner@postgresql.org] On Behalf Of Lorenzo Thurman
> >> I have three tables using date fields. I want to retrieve the oldest
> >> date contained in the tables. Can someone show me an example of a query
> >> that would do that?
>
> > Just do a union and return the min
>
> That's probably not enough detail for a newbie ...
>
> SELECT min(x) FROM
> (
>  SELECT min(datecol1) AS x FROM table1
>  UNION ALL
>  SELECT min(datecol2) AS x FROM table2
>  UNION ALL
>  SELECT min(datecol3) AS x FROM table3
> ) ss;
>
> Exercise for newbie: which of the AS clauses are redundant?

they are all unnecessary :D

select least
(
  (SELECT min(datecol1) FROM table1),
  (SELECT min(datecol2) FROM table2),
  (SELECT min(datecol3) FROM table3)
);

merlin

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Postgres Crash Running PLPGSQL Function on 8.2.3
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: How to disable duplicate columns