SQL MIN and MAX FUNCTIONS

As name indicated, MIN and MAX return minimum and maximum values from the table. MIN and MAX are both aggregate function which are used in SQL statement to retrieve smaller and larger value from the columns.

Let’s understand each with syntax and examples.

MS SQL

Syntax:

SELECT MIN(COLUMN)
FROM TABLE_NAME
WHERE Condition

SELECT MAX(COLUMN)
FROM TABLE_NAME
WHERE Condition

Example:

Original Data in table called “Employee”

Id Employee Code First Name Last name Gender Birth Date
1 EMP_1001 John Peter Male 10-11-1982
2 EMP_1002 Josh Wills Male 09-07-1980
3 EMP_1003 Jeremy Parkar Female 08-09-1990
4 EMP_1004 Aidan Walls Male 05-03-1989
5 EMP_1005 Adam Mondry Male 02-06-1991


MAX Example:

SELECT MAX(Birthdate)
FROM Employee

Data displayed from table “Employee” after above Sql Query executed


Birth Date
02-06-1991


MIN Example:

SELECT MIN(Birthdate)
FROM Employee

Data displayed from table “Employee” after above Sql Query executed


Birth Date
09-07-1980