Get the id of the maximum value

1

In a Mysql table

id valor
1    5
2    15
3    7

I want to get the value of the "id" that has the highest value in the value field. I want it to return the value 2 in this case.

    
asked by anonymous 24.11.2017 / 20:10

1 answer

4

Sort the result by the DESC value and limit to 1:

SELECT
    id
FROM tabela
ORDER BY valor DESC
LIMIT 1;
    
24.11.2017 / 20:15