In this post, we will see how to find the highest or maximum salary in MySQL table.
We have following salary table
select * from salary;
+-------+--------+
| EmpID | salary |
+-------+--------+
| 101 | 1000 |
| 102 | 5000 |
| 103 | 2000 |
| 104 | 1000 |
| 105 | 9000 |
| 106 | 12000 |
| 107 | 10000 |
| 108 | 6000 |
| 109 | 25000 |
| 110 | 4000 |
+-------+--------+
10 rows in set (0.00 sec)
We have to find the highest salary from salary table.
We will use MAX()
function of MySQL to find the maximum salary of the employee.
select max(salary) from salary;
select max(salary) from salary;
+-------------+
| max(salary) |
+-------------+
| 25000 |
+-------------+
1 row in set (0.00 sec)
Above query will return only highest salary but if you want to know which employee has highest or maximum salary then we can use below query.
select Empid,salary from salary where salary=(select max(salary) from salary);
select Empid,salary from salary where salary=(select max(salary) from salary);
+-------+--------+
| Empid | salary |
+-------+--------+
| 109 | 25000 |
+-------+--------+
1 row in set (0.04 sec)
Above MySQL query will return the Employee having maximum or highest salary.