Interviewer And Interviewee Guide

Analyst Integration Interview Question:

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

Submitted by: Administrator
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.
Submitted by:

Read Online Analyst Integration Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.