"=?iso-8859-1?Q?Paul_Wehr?=" <postgresql@industrialsoftworks.com> writes:
> I need to find the minimum of dates in a number of tables, but "min(date)"
> is, of course, an aggregate function. For example:
> select key, min(a.date, b.date, c.date) as first_date
> from table_a a, table_b b, table_c c
> where a.key=b.key and a.key=c.key
Does that really express the computation you want, ie produce a result
only for key values that occur in all three tables?
I was going to suggest
select key, min(date) as first_date from
(select key, date from table_a
union all
select key, date from table_b
union all
select key, date from table_c) subsel
group by key;
but it occurs to me that this produces different results, ie, it will
include key values that only occur in one or two of the tables ...
regards, tom lane