I think you should:
SELECT CASE GREATEST(`id`,`one`, `two`, `three`, `four`, `five`)
WHEN `id` THEN `id`
WHEN `one` THEN `one`
WHEN `two` THEN `two`
WHEN `three` THEN `three`
WHEN `four` THEN `four`
WHEN `five` THEN `five`
ELSE 0
END AS maxcol,
GREATEST(`id`,`one`, `two`, `three`, `four`, `five`) as maxvalue
FROM tbl
it is simple if you do not want to look here: The greatest MySQL value in a row? (I adapted the FROM THAT POST answer to suit your needs, if you have problems, refer to this post anyway)
source
share