SQL MAX Function
Category : TECH Author : Ankur Rastogi Date : Sun Mar 27 2016 Views : 31

SQL MAX Function is used to find the maximum values for any input column_name. MAX aggregate Function is used to find the maximum value present in any column name like highest salary.
Syntax for MAX Function is
SELECT MAX(column_name) FROM table_name;
Let us look on a example for this, Consider table hostel_list which is containing list of hostel details.
+----+-------------------+-----------+----------+
| id | name | occupancy | capacity |
+----+-------------------+-----------+----------+
| 1 | ASHOK BHAVAN | 2 | 1090 |
| 2 | KAILASH BHAVAN | 2 | 990 |
| 3 | RUDRAKSH BHAVAN | 2 | 990 |
| 4 | KAVERI BHAVAN | 1 | 690 |
| 5 | BHAGIRATHI BHAVAN | 4 | 2140 |
| 6 | NARMADA BHAVAN | 6 | 3240 |
| 7 | GANGA BHAVAN | 1 | 780 |
| 8 | YAMUNA BHAVAN | 8 | 4580 |
+----+-------------------+-----------+----------+
Let us find the maximum capacity of an hostel. SQL query for that will be
SELECT MAX(capacity) FROM hostel_list;
+---------------+
| MAX(capacity) |
+---------------+
| 4580 |
+---------------+

SQL MAX Function is used to find the maximum values for any input column_name. MAX aggregate Function is used to find the maximum value present in any column name like highest salary.
Syntax for MAX Function is
SELECT MAX(column_name) FROM table_name;
Let us look on a example for this, Consider table hostel_list which is containing list of hostel details.
+----+-------------------+-----------+----------+
| id | name | occupancy | capacity |
+----+-------------------+-----------+----------+
| 1 | ASHOK BHAVAN | 2 | 1090 |
| 2 | KAILASH BHAVAN | 2 | 990 |
| 3 | RUDRAKSH BHAVAN | 2 | 990 |
| 4 | KAVERI BHAVAN | 1 | 690 |
| 5 | BHAGIRATHI BHAVAN | 4 | 2140 |
| 6 | NARMADA BHAVAN | 6 | 3240 |
| 7 | GANGA BHAVAN | 1 | 780 |
| 8 | YAMUNA BHAVAN | 8 | 4580 |
+----+-------------------+-----------+----------+
Let us find the maximum capacity of an hostel. SQL query for that will be
SELECT MAX(capacity) FROM hostel_list;
+---------------+
| MAX(capacity) |
+---------------+
| 4580 |
+---------------+
Disclaimer: The above content reflect author’s personal views and do not reflect the views of OYEWIKI. Neither OYEWIKI nor any person/organization acting on its behalf is liable to accept any legal liability/responsibility for any error/mislead in this information or any information available on the website. This website in no way accepts the responsibility for any loss, injury, damage, discomfort or inconvenience caused as a result of reliance on any information provided on this website.
If you want to add more comments to the article or you see any thing incorrect please write a comment below and we will surely get back to you.