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 in function is

SELECT MAX ([Column_Name])
FROM [Source]

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

MySQL MAX Example 1

MySQL MAX Example

The Max function in MySQL 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 belongs 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 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 MySQL DISTINCT keyword).