How to find Nth Highest Salary in SQL| How to find 2nd Highest Salary in SQL| SQL Interview Question
ItJunction4all ItJunction4all
12.1K subscribers
8,787 views
0

 Published On Apr 17, 2021

How to find Nth Highest Salary in SQL| How to find 2nd Highest Salary in SQL| SQL Interview Question
In this video , I have explained how to find Nth Highest Salary in SQL in four different ways
1. Nth Highest Salary using Subquery and Dense Rank function
2. Nth Highest Salary using CTE and Dense Rank function
3. Nth Highest Salary using Correlated Subquery
4. Nth Highest Salary using TOP clause in SQL Server

-------------------------------------------------------------------------
Follow me on Social Networking Sites :
-------------------------------------------------------------------------
*Twitter:
  / sunilkr5672  
*Instagram :
  / itjunction4all  

-------------------------------------------------------------------------
Table and Insert SQL Script :
-------------------------------------------------------------------------
CREATE TABLE Employee(
EmpID int ,
EmpName varchar(30) ,
Salary Bigint ,
DeptID int
)
INSERT [dbo].[Employee] ([EmpID], [EmpName], [Salary], [DeptID]) VALUES (1001, N'Mark', 60000, 2)
INSERT [dbo].[Employee] ([EmpID], [EmpName], [Salary], [DeptID]) VALUES (1002, N'Antony', 40000, 2)
INSERT [dbo].[Employee] ([EmpID], [EmpName], [Salary], [DeptID]) VALUES (1003, N'Andrew', 15000,1)
INSERT [dbo].[Employee] ([EmpID], [EmpName], [Salary], [DeptID]) VALUES (1004, N'Peter', 35000, 1)
INSERT [dbo].[Employee] ([EmpID], [EmpName], [Salary], [DeptID]) VALUES (1005, N'John', 55000, 1)
INSERT [dbo].[Employee] ([EmpID], [EmpName], [Salary], [DeptID]) VALUES (1006, N'Albert', 25000, 3)
INSERT [dbo].[Employee] ([EmpID], [EmpName], [Salary], [DeptID]) VALUES (1007, N'Donald', 35000, 3)

-------------------------------------------------------------------------------------------------------------------------------------------------------
#NthHighestSalary #2ndHighestSalary
#SQLInterviewQuestionsandanswers #sqlInterviewQuestions #sqlInterviewQuestionsForTesting #sqlInterviewQuestionsQuery #sqlInterviewQuestionsOnJoins #sqlTechnicalInterviewQuestions #SQLforETLTesters #CommonSqlInterviewQuestions #ETLTesting #ITJUNCTION4ALL #SunilKumar

show more

Share/Embed