MySQL MAX is one of the Aggregate Function, which is used 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.
MySQL MAX Syntax
The basic syntax of the MAX in MySQL is as shown below:
SELECT MAX ([Column_Name]) FROM [Source]
In this article we will show you, How to find Maximum in MySQL with example. For this, We are going to use the below shown data
MySQL MAX Example
The Max function in MySQL returns the maximum value present in the specified column. For example, The following query will return the Maximum, or Highest Yearly Income value from customer details table.
-- MAX in MySQL Example SELECT MAX(Yearly_Income) AS `Maximum Income` FROM customerdetails;
MySQL MAX Function – Group By Example
In general, we use this Max function to check for top performing products belongs to 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 MySQL Maximum Function to find the highest value in each group.
-- MySQL MAX Function Example USE company; SELECT Education, MAX(Yearly_Income) FROM customerdetails GROUP BY Education;
Above SQL Query will group the Customers by their Education, and finds the highest Income in each group
TIP: In MySQL, you can use DISTINCT Keyword along with MAX function to remove the Duplicates. But, it will give the same result as the above (without using DISTINCT keyword).
Thank You for Visiting Our Blog