MAX() function
The MAX() function returns the maximum value for a column in a table or set of rows returned in a query.
Summary:
SELECT MAX(Column_name)
FROM table_name
Example:
Suppose we have a table ‘tbl_employee’
Table name: tbl_Employee
Employee Id | EmpName | Salary | Department |
1 | Ankur | 1200 | Sales |
2 | David | 3400 | Sales |
3 | John | 1500 | HR |
4 | James | 1200 | Production |
5 | Mohan | 4500 | Production |
6 | Ram | 2300 | HR |
- Now we want to know maximum salary from above table then we can use following query with select statement:
SELECT MAX(salary) FROM tbl_Employee
And output will look like this:
4500 |
MIN() function
MIN() is the opposite of MAX() in every regard. The same rules and features of the MAX() function apply to the MIN() function. Important thing is that the lowest value returned for the text depends on the sort order and case sensitivity.
Summary:
SELECT MIN(Column_name)
FROM table_name
Example:
Suppose we have a table ‘tbl_employee’
Table name: tbl_Employee
Employee Id | EmpName | Salary | Department |
1 | Ankur | 1200 | Sales |
2 | David | 3400 | Sales |
3 | John | 1500 | HR |
4 | James | 1200 | Production |
5 | Mohan | 4500 | Production |
6 | Ram | 2300 | HR |
- Now we want to know minimum salary from above table then we can use following query with select statement:
SELECT MIN(salary) FROM tbl_Employee
And output will look like this:
1200 |