Given a Employee Table with two columns
There are multiple ways to get the second highest salary among all Employees.
- Option 1: Use SubquerySELECT MAX(Salary)
WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employee );In this approach, we are getting the maximum salary in a subquery and then excluding this from the rest of the resultset.
- Option 2: Use Not equalsselect MAX(Salary) from Employee
WHERE Salary <> (select MAX(Salary) from Employee )
This is same as option 1 but we are using <> instead of NOT IN.