MySQL Aggregate Function MIN()
The MIN()
function is a MySQL aggregate function that is used to find the minimum or smallest value in a column. In this tutorial, we'll cover the syntax, example, output, explanation, use, important points, and summary of the MIN()
function in MySQL.
Syntax
The syntax for the MIN()
function in MySQL is:
SELECT MIN(column_name)
FROM table_name;
Here, column_name
is the name of the column from which you want to retrieve the minimum value, and table_name
is the name of the table that contains the column.
Example
Let's say we have a table named products
, with columns product_name
and price
. Here's an example query to find the minimum price of a product:
SELECT MIN(price)
FROM products;
Output
When we run the example query above, the output will be the minimum price in the price
column of the products
table.
Explanation
In the example above, we used the MIN()
function to retrieve the minimum value of the price
column in the products
table. This function is useful for finding the smallest or minimum value in a column.
Use
The MIN()
function can be used in a variety of scenarios, such as:
- Finding the smallest price or value in a column
- Finding the earliest date in a column
- Finding the lowest score or grade in a column
Important Points
Here are a few important things to keep in mind regarding the MIN()
function in MySQL:
- The values in the column must be of a comparable data type, such as numbers or dates.
- Null values are excluded from the calculation.
- If there are multiple values that match the minimum value, the function will return only the first one.
Summary
The MIN()
function in MySQL is a useful aggregate function that can be used to find the minimum or smallest value in a column. It is commonly used to retrieve the minimum price, value, or date in a table. In this tutorial, we covered the syntax, example, output, explanation, use, important points, and summary of the MIN()
function in MySQL.