Jacek Francuz
Jacek Francuz

Reputation: 2498

Is there MAX function for rows - not for columns?

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

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

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

Upvotes: 4

Views: 161

Answers (2)

xdazz
xdazz

Reputation: 160893

SELECT GREATEST(column1, column2, column3) as max_value

Upvotes: 4

Martin Smith
Martin Smith

Reputation: 453648

You need the GREATEST function

SELECT GREATEST(column1, column2, column3) AS X

Upvotes: 9

Related Questions