Is there a MAX function for rows - not columns?

I need to get the maximum value of a certain number of columns (for each row). Is it possible to do this in MySQL?

For example: SELECT MAX(column1, column2, column3) .

I'm not looking for a MAX function that aggregates the values โ€‹โ€‹of a given column. I need to aggregate the values โ€‹โ€‹of different columns for each row.

+4
source share
2 answers

You need a GREATEST function

 SELECT GREATEST(column1, column2, column3) AS X 
+8
source

SELECT GREATEST(column1, column2, column3) as max_value

+4
source

All Articles