SQL MAX() Function
The SQL MAX() is a function, and return the largest or highest value of a numeric table column from query result.
The SQL MAX() function is supports only numeric column.
It can be used in SQL SELECT statement as well in SQL WHERE clause.
Related Links
You can also search these topics using sql where max date, select max id from table, sql max of two values, sql server select max, get max value in sql, sql select max value, select max value from table.
SQL MAX() Syntax
The below syntax is used to select specific column from the specific table.
SELECT MAX(column_name1) FROM table_name;
Sample Database Table - Employee
ID | EmpName | Designation | Dept | JoinYear | Salary |
---|---|---|---|---|---|
1 | Vidyavathi | Database Designer | MySQL | 2014 | 15440 |
2 | Harish Karthik | Employee | HTML | 2015 | 17540 |
3 | Hari Krishnan | Manager | Oracle | 2015 | 17330.2 |
4 | Sakunthala | Web Mining | Java | 2012 | 5990.3 |
5 | Hanumanthan | Project Lead | Java | 2012 | 8510.9 |
6 | Keshavan | Mobile Database | HTML | 2015 | 16910.2 |
SQL MAX() Example
The following SQL SELECT statement find the largest or maximum value of "Salary" column from the "Employee" table:
SELECT
MAX(Salary) As 'Maximum Salary'
FROM Employee;
The result of above query is:
Maximum Salary |
---|
17540 |
SQL MAX() Example - Using Group By Clause
The following SQL SELECT statement find the highest or maximum salary in all "Dept" column from the "Employee" table:
SELECT
Dept, MAX(Salary) As 'Maximum Salary'
FROM Employee
GROUP BY Dept;
The result of above query is:
Dept | Maximum Salary |
---|---|
HTML | 17540 |
Java | 8510.9 |
MySQL | 15440 |
Oracle | 17330.2 |
Related Links
You can also search these topics using sql get maximum value, max keyword in sql, sql query max value, aggregate functions in sql, sql aggregate functions examples.