max(max(col1), max(col2), ...) does not work I have a table with three integer columns:

select max(col1), max(col2), max(col3) from mytable


I want the max of both three columns. But this does not work:

select max(max(col1), max(col2), max(col3)) from mytable


How to get this done?

I use PostgreSQL, but I hope that this can be solved with standard SQL.
That should be GREATEST(), not MAX(). MAX() is for aggregating over values from rows, GREATEST() is for aggregating over a list of values (from columns, expressions).

You can either find the 3 max values, one for each column and then the greatest of the three:

select greatest(max(col1), max(col2), max(col3)) 
from mytable ;


or find the greatest value in each row and then the max over all of them:

select max(greatest(col1, col2, col3)) 
from mytable ;