Re: NEWBIE: How do I get the oldest date contained in 3 tables - Mailing list pgsql-general

From Tom Lane
Subject Re: NEWBIE: How do I get the oldest date contained in 3 tables
Date
Msg-id 10286.1176151114@sss.pgh.pa.us
Whole thread Raw
In response to Re: NEWBIE: How do I get the oldest date contained in 3 tables  ("Dann Corbit" <DCorbit@connx.com>)
Responses Re: NEWBIE: How do I get the oldest date contained in 3 tables  ("Merlin Moncure" <mmoncure@gmail.com>)
Re: NEWBIE: How do I get the oldest date contained in 3 tables  (Lorenzo Thurman <lorenzo@diespammerhethurmans.com>)
List pgsql-general
"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?

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: join by char(16) or by bytea?
Next
From: Tom Lane
Date:
Subject: Re: Can you combine text variable together to referenece a VIEW name ?