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

From: Lorenzo Thurman <lorenzo(at)diespammerhethurmans(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: NEWBIE: How do I get the oldest date contained in 3 tables
Date: 2007-04-10 00:21:37
Message-ID: 5t1re4-554.ln1@Hedley.internal.thethurmans.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Brent Wood wrote:
> Lorenzo Thurman wrote:
>> 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?
> You could write a custom function doing the same sort of thing, or
> (perhaps more portable) use generic sqls & views like:
>
> create view min_dates as
> select min(date1) from table1as date_1
> union
> select min(date2) from table2 as date_1
> union select min(date3) from table3 as date_1;
>
> then either:
>
> select min(date_1) from min_dates;
>
>
> or
>
> create view min_date as
> select min(date_1) as min_date
> from min_dates;
>
> then just:
>
> select min_date from min_date;
>
>
>
> Cheers
>
> Brent Wood
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>
Thanks for the tip!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Geoffrey 2007-04-10 00:31:42 Re: backend reset of database
Previous Message Listmail 2007-04-09 23:36:02 Re: programmatic way to fetch latest release for a given major.minor version