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.
The below given are the SQL Server Min() and Max () examples.
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;
UserId | GiveName | MiddleName | FamilyName | Age | Status |
1 | Mohit | Sharma | 28 | New | |
2 | Rohit | Kumar | Jain | 34 | Closed |
3 | Snehashish | Gupta | 31 | Pending | |
4 | Rajeev | Malhotra | 34 | Closed |
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