How can we fetch a second highest salary of an employee from a MySQL table?


To understand this concept, we are using the data from table ‘Salary’ as follows −

mysql> Select * from Salary;
+--------+--------+
| Name   | Salary |
+--------+--------+
| Gaurav |  50000 |
| Rahul  |  40000 |
| Ram    |  45000 |
| Raman  |  45000 |
+--------+--------+
4 rows in set (0.00 sec)

mysql> Select * from salary12345 order by salary DESC limit 1 offset 1;
+-------+--------+
| name  | Salary |
+-------+--------+
| Raman |  45000 |
+-------+--------+
1 row in set (0.00 sec)

Updated on: 22-Jun-2020

165 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements