MIN() in SQL
Returns the smallest value from a specified column or expression, ignoring NULL values.
Syntax
Return type
MIN() Function Example
What is MIN() in SQL?
The MIN()
function in SQL returns the smallest value from a specified column or expression, ignoring NULL values. It is commonly used for finding the lowest price, minimum salary, earliest date, or smallest numeric value in a dataset.
This function is supported in SQL Server, MySQL, PostgreSQL, and Oracle.
The MIN()
function is widely used in data analysis, reporting, and performance tracking.
Parameters:
expression: Column name or expression to evaluate
Example Use Cases:
-- Find lowest product price
-- Get earliest order date
-- Find minimum rating per product
Notes:
Behavior: Ignores NULL values in comparison
Performance Considerations: Benefits from indexes
Version Info: Core aggregation function available in all major DBMS
Deprecated/Recommended Alternatives: None
Error Handling:
Error: Returns NULL if all values are NULL
Recommendation: Use COALESCE or IF NULL for NULL handling
Supported Databases:
DBMS
Function / Syntax
Example
Behavior with NULL
MySQL
MIN(expression)
MIN(salary)
Ignores NULL
PostgreSQL
MIN(expression)
MIN(salary)
Ignores NULL
SQL Server
MIN(expression)
MIN(salary)
Ignores NULL
SQLite
MIN(expression)
MIN(salary)
Ignores NULL
BigQuery
MIN(expression)
MIN(salary)
Ignores NULL
Snowflake
MIN(expression)
MIN(salary)
Ignores NULL
Athena
MIN(expression)
MIN(salary)
Ignores NULL
Related Functions:
MAX()
Returns the largest value from a specified column or expression, ignoring NULL values.
AVG()
Calculates the arithmetic mean (average) of all non-null values in a specified column or expression.
COUNT()
Counts the number of rows or non-null values in a specified column. COUNT(*) counts all rows including nulls, while COUNT(column) counts non-null values in the specified column.
SUM()
Calculates the total sum of all values in a specified column or expression, ignoring NULL values.