Re: What can I use as a [non-aggregate] minimum function - Mailing list pgsql-general

From Tom Lane
Subject Re: What can I use as a [non-aggregate] minimum function
Date
Msg-id 28156.1008025622@sss.pgh.pa.us
Whole thread Raw
In response to What can I use as a [non-aggregate] minimum function  ("Paul Wehr" <postgresql@industrialsoftworks.com>)
Responses Re: What can I use as a [non-aggregate] minimum function
best solution for BLOB storage across networks?
List pgsql-general
"=?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

pgsql-general by date:

Previous
From: Glen Eustace
Date:
Subject: Re: Weird problem - possibly a bug.
Next
From: Andrew Gould
Date:
Subject: Re: Need SQL help, I'm stuck.