MySQL MAX Function

MySQL MAX Aggregate Function is to find the maximum value of total records (or rows) selected by the SELECT Statement. For example, If you want to find the top-selling product in your Store, then you can use this Maximum function. The basic syntax of the MySQL MAX function to find the maximum is

SELECT MAX ([Column_Name])
FROM [Source]

How to find Maximum with an example. For this MySQL MAX function demo, We are going to use the below-shown data.

Customer Table 1

MySQL MAX Function Example

The Max function returns the maximum value present in the specified column. For example, The following query returns the Maximum or Highest Yearly Income value from the customer details table.

SELECT MAX(Yearly_Income) AS `Maximum Income`
FROM customerdetails;
MySQL MAX Function Example 1

MAX Group By Example

In general, we use this Aggregate method to check for top-performing products belonging to a particular category, or color, etc.

In this situation, we can use Group By Clause to group the products by color or category. Next, we use this MySQL MAX Function to find the highest value in each group by.

USE company;
SELECT  Education,
        MAX(Yearly_Income)
FROM customerdetails
GROUP BY Education;

The above Maximum query group the Customers by their Education and finds the highest Income in each category.

MySQL MAX Function GroupBy Clause Example 2

You can use DISTINCT Keyword along with this to remove the Duplicates. But, the SELECT Statement gives the same result as the above (without using the MySQL DISTINCT keyword).