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

From: "John D(dot) Burger" <john(at)mitre(dot)org>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: NEWBIE: How do I get the oldest date contained in 3 tables
Date: 2007-04-10 19:47:26
Message-ID: 20B6F678-B343-4C1C-A6AA-8F51E1191CA1@mitre.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>> 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?
>
> Um, all of them?

Yah, but only if you do this:

SELECT min(*) FROM
(
SELECT min(datecol1) FROM table1
UNION ALL
SELECT min(datecol2) FROM table2
UNION ALL
SELECT min(datecol3) FROM table3
) ss;

Otherwise you need the first one, I think, unless you want to rely on
PG's naming conventions for columns, then you could do:

select min(min) from
(
SELECT min(datecol1) FROM table1
UNION ALL
...
)

- John D. Burger
MITRE

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Florian G. Pflug 2007-04-10 20:10:24 Re: passing arrays to shared object functions
Previous Message Reece Hart 2007-04-10 19:24:17 storing checksums in a database