MIN
MIN(expression)
Section titled “MIN(expression)”- expression: Refers to the column or set of columns in the table. The `MIN()` function will return the smallest value found in this specified column or set of columns.
Example
Section titled “Example”SELECT MIN(salary) FROM employee;Output
Section titled “Output”85000Explanation
Section titled “Explanation”This query is used to find the minimum value in the ‘salary’ column of the ‘employee’ table.
MIN(expression) OVER ([PARTITION BY partition_expression] [ORDER BY sort_expression [ASC | DESC]] [ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW])
Section titled “MIN(expression) OVER ([PARTITION BY partition_expression] [ORDER BY sort_expression [ASC | DESC]] [ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW])”- expression: Refers to any valid expression that represents the column from which the minimum value has to be found.
- partition by partition_expression: This is an optional clause that separates the data into different partitions, as indicated by partition_expression. This is useful for analyzing sections of data.
- order by sort_expression [asc | desc]: This optional clause dictates the order in which the data is sorted before the minimum value is found. The sort_expression determines the column by which the data is sorted. ASC or DESC indicates ascending or descending order respectively.
- rows between unbounded preceding and current row: This optional clause defines a sliding window of data to operate on. “UNBOUNDED PRECEDING” indicates that the window starts at the first row of the partition, and “CURRENT ROW” means the window ends at the current row. The minimum value will then be calculated from this defined section of data.
Example
Section titled “Example”SELECT MIN(unit_price) FROM products;Output
Section titled “Output”min------1.23Explanation
Section titled “Explanation”In the given example, the MIN() function is used to find the lowest unit price amongst all products within the ‘products’ table. The value ‘1.23’ is the minimum unit price found.
MIN( [ ALL | DISTINCT ] expression ) OVER ( [ partition_by_clause ] order_by_clause rows_range_clause )
Section titled “MIN( [ ALL | DISTINCT ] expression ) OVER ( [ partition_by_clause ] order_by_clause rows_range_clause )”- all: This keyword is used when you want to calculate the minimum value from all possible values within the specified expression.
- distinct: The DISTINCT keyword is used when you want to calculate the minimum value from distinct values within the specified expression.
- expression: The expression parameter is used to specify the column or set of columns upon which the MIN function would be applied.
- over: The OVER keyword is used to signify that we are about to describe the windowing clause, included within the parentheses after the OVER keyword.
- partition_by_clause: This clause is used to divide the query result set into partitions. The function is applied to each partition separately and computation is reset for each partition.
- order_by_clause: The order_by_clause parameter allows you to specify the column or columns used to order the result set.
- rows_range_clause: By using the rows_range_clause, one specifies the start and end points within the partition for the window frame where the function will calculate the result.
- min: This SQL function returns the smallest value of the selected column.
Example
Section titled “Example”SELECT MIN(Salary) AS MinimumSalaryFROM Employees;Output
Section titled “Output”MinimumSalary15000Explanation
Section titled “Explanation”The MIN() function returns the smallest value of the selected column, in this case, it returns the lowest salary from the Employees table.
MIN(expression)
Section titled “MIN(expression)”- expression: It refers to the column or set of values on which the MIN function is going to be computed. This can refer to a column name, the result of another function, or a mathematical formula.
Example
Section titled “Example”SELECT MIN(salary) FROM employees;Output
Section titled “Output”| MIN(SALARY) ||-------------|| 2000 |Explanation
Section titled “Explanation”This SQL statement returns the minimum value of the “salary” column from the “employees” table. The MIN function in SQL returns the smallest value of the selected column.
MIN(expression)
Section titled “MIN(expression)”- expression: The portion of the SQL statement that specifies the column of a table or query which the function will operate on. The MIN function takes this expression parameter, and returns the smallest value in the set of values in the specified column.
Example
Section titled “Example”SELECT MIN(salary) FROM employees;Output
Section titled “Output”35000Explanation
Section titled “Explanation”The above SQL query retrieves the minimum value from the ‘salary’ column of the ‘employees’ table. In this case, the lowest salary is 35000.