MIN (TSQL Function)
Returns the minimum value of a column.
Syntax
MIN ( expression )
Arguments
- expression
- is an expression of any type.
Return Types
Returns the type of expression.
Remarks
NULL values are ignored.
Examples
DECLARE @t TABLE (
id INT NOT NULL PRIMARY KEY,
name VARCHAR(30),
birthdate DATE
);
INSERT INTO @t VALUES (10, 'John', '19700301'),
(20, 'Fred', '20021123'),
(40, 'Alex', '19950712'),
(50, 'Maria', '19700322'),
(30, 'Alice', '19950101'),
(15, NULL, '19950101');
SELECT YEAR(birthdate), MIN(id), MIN(name), MIN(birthdate), COUNT(*)
FROM @t
GROUP BY YEAR(birthdate)
ORDER BY YEAR(birthdate);
The result is:
$g$0 |$min$1 |$min$2 |$min$3 |$count$4 |
-----------+-----------+------------------------------+----------+-----------+
1970| 10|John |1970-03-01| 2|
1995| 15|Alex |1995-01-01| 3|
2002| 20|Fred |2002-11-23| 1|
(3 row(s) affected)