Sunday 7 August 2016

Find 2nd max salary



I am going to use following sample data.

mysql> SELECT * FROM employee; 
+----+--------------+------------+------------+
| id | firstName    | lastName   | salary     |
+----+--------------+------------+------------+
|  1 | Hari Krishna | Gurram     |   12345.67 |
|  2 | Rama Devi    | Gurram     | 1234578.67 |
|  3 | Lakshmana    | Rao        | 9876543.67 |
|  4 | Rama         | Krishna    | 1234587.67 |
|  5 | Sowmya       | asd        | 1238745.67 |
|  6 | Jyotsna      | PS         |   76543.67 |
|  7 | Gireesh      | Amara      |   87698.00 |
|  8 | Sravani      | Nidamanuri |  987654.00 |
|  9 | Saranya      | Amara      | 1987654.00 |
| 10 | Sudhir       | Sami       |  876543.00 |
| 11 | Kiran        | Darsi      |   76549.00 |
+----+--------------+------------+------------+
11 rows in set (0.00 sec)
 

mysql> SELECT MAX(salary) FROM employee WHERE salary < (SELECT MAX(salary) FROM employee);
+-------------+
| MAX(salary) |
+-------------+
|  1987654.00 |
+-------------+
1 row in set (0.00 sec)









Previous                                                 Next                                                 Home

No comments:

Post a Comment