SQL Server Functions Min() and Max() on table result set

SQL Server provides some SQL Functions to manipulate the table result data.

SQL Server Min() Function allows to retrieve the table result set based on the condition of smallest / low value

SQL Server Max() Function allows to retrieve the table result set based on the condition of largest / high value.

Lets go through few SQL Query as example.

SQL Server Min () Syntax:

SELECT MIN(column_name)
FROM table_name
WHERE condition;

SQL Server Max() Syntax:

SELECT MAX(column_name)
FROM table_name
WHERE condition;

UserIdGiveNameMiddleNameFamilyNameAgeStatus
1Mohit Sharma28New
2RohitKumar Jain34Closed
3Snehashish Gupta31Pending
4Rajeev Malhotra34Closed
SELECT MIN(age)
FROM oracleappshelpUsers;

Output :
Age 
28
SELECT MIN(age)
FROM oracleappshelpUsers 
WHERE Status ='Pending';

Output: 
Age 
31
SELECT MAX(age)
FROM oracleappshelpUsers;

Output: 
Age
34
SELECT MAX(age)
FROM oracleappshelpUsers
where status ='New';

Output: 
Age
28

Bookmark and Share