MIN Function in SQL - sql - sql tutorial - learn sql
- The MIN() function will return the smallest value of the selected column.
- The MIN function will be used to find the minimum value in an expression.
- In other words, SQL MIN function will be used to find out the record with minimum value among a record set.
- The syntax for the MIN function is,
- <expression> can be a column name or an arithmetic operation. An arithmetic operation can include more than one column, such as ("column1" - "column2").
- It is also possible to have one or more columns in addition to the MIN function in the SELECT statement. In those cases, these columns need to be part of the GROUP BY clause as well:
- We use the following table for our examples.
Example 1: MIN function on a column
- To find the minimum sales amount, we type in,
- 250 represents the minimum value of all Sales entries: 1500, 250, 300, and 700.
Example 2: MIN function on an arithmetic operation
- Assume that sales tax is 10% of the sales amount, we use the following SQL statement to get the minimum sales tax amount:
- SQL will first calculate "Sales*0.1" and then apply the MIN function to the result for the final answer.
Example 3: MIN function with a GROUP BY clause
- To get the minimum amount of sales for each store, we type in,