Analyst Integration Question:

Download Job Interview Questions and Answers PDF

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

Integration Programmer Interview Question
Integration Programmer Interview Question

Answer:

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.

Download Integration Programmer Interview Questions And Answers PDF

Previous QuestionNext Question
Explain stateless system?How to find if a number is power of two, without using arithmetic operator?