Let's say I have two columns in my table, column A and B.
+-----+-----+-----+
| ID | A | B |
+-----+-----+-----+
| 1 | 500 | 681 |
+-----+-----+-----+
| 2 | 980 | 101 |
+-----+-----+-----+
| 3 | 110 | 981 |
+-----+-----+-----+
If I do the following select, I can return the highest value
select GREATEST(MAX(A), MAX(B)) as bigger FROM valores
In the above example the value 981
returns from select.
However I'd like to also return the ID for the line that has the highest value. I'm doing the following select:
select valor.*, GREATEST(MAX(A), MAX(B)) as bigger FROM valores as valor
It still returns me the value 981
, but it does not return the ID of the row that has the largest value, but the ID of the first row of the database.
Then how do I make the select to return the highest value among the columns and the ID for the row of that highest value