MIN

Transact-SQL Reference

Transact-SQL Reference

MIN

Returns the minimum value in the expression.

Syntax

MIN ( [ ALL | DISTINCT ] expression )

Arguments

ALL

Applies the aggregate function to all values. ALL is the default.

DISTINCT

Specifies that each unique value is considered. DISTINCT is not meaningful with MIN and is available for SQL-92 compatibility only.

expression

Is a constant, column name, or function, and any combination of arithmetic, bitwise, and string operators. MIN can be used with numeric, char, varchar, or datetime columns, but not with bit columns. Aggregate functions and subqueries are not permitted.

Return Types

Returns a value same as expression.

Important  Distinct aggregates, for example AVG(DISTINCT column_name), COUNT(DISTINCT column_name), MAX(DISTINCT column_name), MIN(DISTINCT column_name), and SUM(DISTINCT column_name), are not supported when using CUBE or ROLLUP. If used, Microsoft® SQL Server™ returns an error message and ends the query.

Remarks

MIN ignores any null values.

With character data columns, MIN finds the value that is lowest in the sort sequence.

Examples

This example returns the book with the lowest (minimum) year-to-date sales.

USE pubs
GO
SELECT min(ytd_sales)
FROM titles
GO

Here is the result set:

----------- 
111         

(1 row(s) affected)

See Also

Aggregate Functions