MySQL MIN Aggregate Function is 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
SELECT MIN ([Column_Name]) FROM [Source]
The Min Function ignores the NULL values while finding the Minimum value. How to find Minimum in MySQL with an example using 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 returns the Minimum or Lowest value present in the Sales column from the 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 the least performing products belongs to a 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;
The above MIN Aggregate Function query group the Customers by their profession, and finds the least sales in each group
You can use DISTINCT Keyword along with MIN function to remove the Duplicates from the specified column Name. But, it gives the same result as the above SELECT Statement (without using MySQL DISTINCT keyword).