MySQL MIN is one of the Aggregate Function, which is used to find the Minimum value of total rows (or records) selected by the SELECT Statement. For example, If you want to find the least performing product in your Store then you can simply use this Minimum function.
MySQL Min Syntax
The basic syntax of the MIN in MySQL is as shown below:
SELECT MIN ([Column_Name]) FROM [Source]
TIP: The Minimum Function will ignore the NULL values, while finding the Minimum value.
In this article we will show you, How to find Minimum in MySQL with example. For this, We are going to use the below shown data
MySQL MIN Example
The Min function in MySQL returns the minimum value present in the specified column. For example, The following query will return the Minimum, or Lowest value present in Sales column from customer details table.
-- MIN in MySQL Example SELECT MIN(Sales) AS `Minimum Sales` FROM customerdetails;
MySQL MIN Function – Group By Example
In general, we use this Min function to check for least performing products belongs to particular color or category etc. In this situation, we can use Group By Clause to group the products by color or category. Next, we use MySQL Minimum Function to find the lowest value in each group. Let us see the Example
-- MySQL MIN Function Example USE company; SELECT Profession, MIN(Sales) FROM customerdetails GROUP BY Profession;
Above SQL Query will group the Customers by their profession, and finds the least sales in each group
TIP: In MySQL, you can use DISTINCT Keyword along with MIN function to remove the Duplicates from the specified column Name. But, it will give the same result as the above (without using DISTINCT keyword).
Thank You for Visiting Our Blog