Get the id of the maximum value

Asked

Viewed 390 times

1

In a Mysql table

id valor
1    5
2    15
3    7

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

1 answer

4


Sort the result by DESC and limit to 1:

SELECT
    id
FROM tabela
ORDER BY valor DESC
LIMIT 1;
  • Correct. was trying to select id from Where table MAX(value);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.