Assume all value columns have the same datatype. I would like the highest of all values with the id in the results of a SELECT query.
Table Structure:
table_a: id, value1, value2, value3, value4, value5
Example data:
id, value1, value2, value3, value4, value5
2, 125, 256, 133, 400, 67
3, 14, 14, 14, 3, 6
4, 325, 441, 441, 975, 3
Example desired results:
id, highest_value
2, 400
3, 14
4, 975
I started down the path of a CASE statement but that got messy fast. I tired a sub-select but failed in getting that to work. Is there a clean way to compare several column values to each other?
In this case greatest function will do the work.
Result: