Back to Library

MIN() in SQL

Returns the smallest value from a specified column or expression, ignoring NULL values.

Syntax

MIN(expression)
Return type
Same as input type (number, date, string, etc.)

MIN() Function Example

SELECT MIN(salary) FROM employees; 
-- Output: 30000.00 (lowest salary)

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

SELECT MIN(price) AS lowest_price FROM products; 
-- Output:
lowest_price
------------
    $9.99

-- Get earliest order date 

SELECT MIN(order_date) AS first_order FROM orders; 
-- Output:
first_order
-----------------
2023-01-15 08:30:22

-- Find minimum rating per product 

SELECT product_id, MIN(rating) AS lowest_rating FROM reviews GROUP BY product_id;
-- Output:
product_id    product_name      lowest_rating
----------    -------------     -------------
P100          Coffee Maker           2.0
P101          Headphones            1.5
P102          Phone Charger         3.0
P103          Laptop Stand          2.5
P104          Mouse Pad             3.5

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:

STDEV()

Calculates the standard deviation (population or sample) of a set of numeric values.

Calculates the standard deviation (population or sample) of a set of numeric values.

Calculates the standard deviation (population or sample) of a set of numeric values.

Calculates the standard deviation (population or sample) of a set of numeric values.

VARIANCE()

Calculates the statistical variance (population or sample) of a set of numeric values.

Calculates the statistical variance (population or sample) of a set of numeric values.

Calculates the statistical variance (population or sample) of a set of numeric values.

Calculates the statistical variance (population or sample) of a set of numeric values.

STRING_AGG()

Concatenates values from multiple rows into a single string, with specified delimiter.

Concatenates values from multiple rows into a single string, with specified delimiter.

Concatenates values from multiple rows into a single string, with specified delimiter.

Concatenates values from multiple rows into a single string, with specified delimiter.

GROUP_CONCAT()

Concatenates values from multiple rows into a single string, with optional delimiter and ordering.

Concatenates values from multiple rows into a single string, with optional delimiter and ordering.

Concatenates values from multiple rows into a single string, with optional delimiter and ordering.

Concatenates values from multiple rows into a single string, with optional delimiter and ordering.

MIN()

Returns the smallest value from a specified column or expression, ignoring NULL values.

Returns the smallest value from a specified column or expression, ignoring NULL values.

Returns the smallest value from a specified column or expression, ignoring NULL values.

Returns the smallest value from a specified column or expression, ignoring NULL values.

One place for all your queries,
directly on your SQL editor