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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Dann Corbit" <DCorbit(at)connx(dot)com>
Cc: "Lorenzo Thurman" <lorenzo(at)diespammerhethurmans(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: NEWBIE: How do I get the oldest date contained in 3 tables
Date: 2007-04-09 20:38:34
Message-ID: 10286.1176151114@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Dann Corbit" <DCorbit(at)connx(dot)com> writes:
>> owner(at)postgresql(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-04-09 20:41:56 Re: Can you combine text variable together to referenece a VIEW name ?
Previous Message Tom Lane 2007-04-09 20:33:46 Re: join by char(16) or by bytea?