Answers

Question and Answer:

  Home  Analyst Integration

⟩ Write SQL query to find second highest salary in employee table?

This is one of the classic question from SQL interviews, event it's quite old it is still interesting and has lots of follow-up you can use to check depth of candidate's knowledge. You can find second highest salary by using correlated and non-correlated sub query. You can also use keyword's like TOP or LIMIT if you are using SQL Server or MySQL, given Interviewer allows you. The simplest way to find 2nd highest salary is following :

SELECT MAX(Salary) FROM Employee WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employee)

This query first find maximum salary and then exclude that from list and again finds maximum salary. Obviously second time, it would be second highest salary.

 160 views

More Questions for you: