AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL MIN Function |
|
SQL > SQL Functions >
MIN Function
The MIN function is used to find the minimum value in an expression. The SQL MIN function returns the smallest value in a column or expression — use it alone for an overall minimum or pair it with GROUP BY to find the minimum value within each group.
SyntaxThe 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: ExamplesWe use the following table for our examples. Table Store_Information
Example 1: MIN function on a columnTo find the minimum sales amount, we type in, Result:
250 represents the minimum value of all Sales entries: 1500, 250, 300, and 700. Example 2: MIN function on an arithmetic operationAssume that sales tax is 10% of the sales amount, we use the following SQL statement to get the minimum sales tax amount: Result:
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 clauseTo get the minimum amount of sales for each store, we type in, Result:
Frequently Asked QuestionsQ: What does the SQL MIN function do? Q: Can MIN be used with GROUP BY? Q: Does MIN work with text (string) columns? Q: What is the difference between MIN and MAX?
|
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.