Skip to content

sql_func_min

The MIN() function is an aggregate function that returns the minimum (smallest) value of an expression in a set of rows. This expression is typically a column name.

MIN() can be used with numeric, string, or date/time columns. For strings, it typically returns the first value alphabetically. For dates, it returns the earliest date/time.

NULL values in the specified column are ignored by the MIN() function.

SELECT MIN(expression)
FROM table_name
WHERE condition;

The expression is usually a column name. The WHERE clause is optional; if omitted, MIN() considers all rows in the table.

We will use the Northwind sample database for our examples, focusing on the “Products” table.

Below is a selection from the “Products” table:

ProductID
ProductName
SupplierID
CategoryID
Unit
Price
ReleaseDate
1
Chais
1
1
10 boxes x 20 bags
18.00
2023-01-15
2
Chang
1
1
24 - 12 oz bottles
19.00
2023-02-20
3
Aniseed Syrup
1
2
12 - 550 ml bottles
10.00
2022-12-05
4
Chef Anton's Cajun Seasoning
2
2
48 - 6 oz jars
22.00
2023-03-01
5
Chef Anton's Gumbo Mix
2
2
36 boxes
21.35
2023-01-20
  1. Find the lowest price of any product:

The following SQL statement finds the minimum value in the “Price” column from the “Products” table.

SELECT MIN(Price) AS SmallestPrice
FROM Products;

This query will return 10.00 based on the sample data (Aniseed Syrup).

  1. Find the earliest release date of any product:
SELECT MIN(ReleaseDate) AS EarliestReleaseDate
FROM Products;

This query will return 2022-12-05 based on the sample data.

  1. Find the product name that comes first alphabetically (among products in CategoryID 1):
SELECT MIN(ProductName) AS FirstProductNameInCategory1
FROM Products
WHERE CategoryID = 1;

Based on the sample (Chais, Chang), this would return Chais.

Practical Application:

MIN() is useful for finding the lowest value in a dataset, such as the cheapest product, the earliest transaction date, or the lowest score. Like other aggregate functions, it is often used with the GROUP BY clause to find minimum values within different categories (e.g., the minimum price for each product category).