get max value in mysql code example
Example 1: mysql find max value row
SELECT t1.*
FROM employees t1
INNER JOIN (
SELECT id, max(salary) AS salary FROM employees GROUP BY id
) t2 ON t1.id = t2.id AND t1.salary = t2.salary;
Example 2: mysql get max value and id
SELECT a.id, a.rev, a.contents
FROM YourTable a
INNER JOIN (
SELECT id, MAX(rev) rev
FROM YourTable
GROUP BY id
) b ON a.id = b.id AND a.rev = b.rev
Example 3: mysql max()
USE world;
SELECT MAX(Population) AS 'Maximum Value'
FROM City
WHERE CountryCode = 'THA';