SELECT max(t.a),t.b
from(
SELECT 10 as a,1 as b,1 as c
UNION ALL
SELECT 20,2,1
UNION ALL
SELECT 30,3,2
UNION ALL
SELECT 40,4,2 ) as t
order by b desc;
result = 40,1,1
result needed = 40,4,2
20,2,1
result to return group by column c get the max of a and the b column with it .
2
Answers
Seems you need the first row when ordered:
The query in the questions seems incorrect, it will fail with sql_mode=only_full_group_by enabled, which I strongly recommended to be enabled.
If you want to handle ties , you could use:
https://dbfiddle.uk/bvCKF0od
On MySQL < 8.0, to handle ties you could use:
https://dbfiddle.uk/_e97v_zi