Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

Um, all of them?

Yah, but only if you do this:

SELECT min(*) FROM
(
 SELECT min(datecol1) FROM table1
 UNION ALL
 SELECT min(datecol2) FROM table2
 UNION ALL
 SELECT min(datecol3) FROM table3
) ss;

Otherwise you need the first one, I think, unless you want to rely on PG's naming conventions for columns, then you could do:

select min(min) from
(
 SELECT min(datecol1) FROM table1
 UNION ALL
 ...
)

- John D. Burger
  MITRE




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux