Home >> MySql >> Select Rows with max value for each group in MySql

Select Rows with max value for each group in MySql

Find a maximum value for a certain column.

Example-1

SELECT MAX(price) FROM products

Example-2

Employee Table

Name       City              Salary
Raj            Delhi             200000
Ravi          Delhi             10000
Ram          Lucknow       30000
Suresh      Lucknow       400000

Solution

SELECT city,MAX(salary) FROM employee GROUP BY city;
 
Output
City            Salary
Delhi           200000
Lucknow     400000

Post Your Comment

Next Questions
How to find the sum of values in a column
How do you find the sum of all the values in a column
How to find absolute value of a column
How do I get the absolute value of a column
How to find round value
How to get rounded data
How to find square root of a number
How to find the greatest value in a list
How to find the least value in a list
How To Find e raised to the power of the specified number
How to find a value extracted from a date
How to find a value extracted from a date or datetime
How to find a value extracted from an internal value

Copyright ©2022 coderraj.com. All Rights Reserved.