SQL query to find the second highest salary?

There are multiple way to find the second highest salary from Oracle database.

  • Here first we have created one employee table.
  • In that table there are 5 column id, name, age, address and salary.

          Select * from Employee;

Employee data

Using Subquery :-

select MAX(Salary) from Employee where Salary NOT IN (select MAX(Salary) from Employee);

  • Here we are getting the maximum salary from a Subquery method.
  • First we will find the highest salary in the table and then we will nest that query to a Subquery to find the second highest salary in SQL.

second max salary

Using Not equals <> :-

select MAX(Salary) from Employee where Salary <> (select MAX(Salary) from Employee);

  • Here first we will find the highest salary in the table then use not equals(<>) to get max salary in a Subquery.
  • Then we find the second highest salary in SQL.

second max salary