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
right now I'm using:
case
when a.date < b.date and a.date < c.date then a.date
when b.date < c.date then b.date
else c.date
end
But there must be a better way. I've even looked into createing a
recursive function using an date[] as an argument (since I don't know how
to specify a function with a variable number of arguments)
Sorry if this is a FAQ but muc.lists.postgres doesn't return anything
useful, and the searchable archive seems to be down.
Thanks,
-paul