Part 1 How to find nth highest salary in sql
If you are a foodie like me, I am sure you will enjoy the recipes on my friend's YouTube channel. If you find them useful, please subscribe and share to support her. She's really good at what she does. / @aarvikitchen5572 Link for all dot net and sql server video tutorial playlists / kudvenkat Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspo... This is a very common SQL Server Interview Question. There are several ways of finding the nth highest salary. By the end of this video, we will be able to answer all the following questions as well. How to find nth highest salary in SQL Server using a Sub-Query How to find nth highest salary in SQL Server using a CTE How to find the 2nd, 3rd or 15th highest salary Let's use the following Employees table for this demo Use the following script to create Employees table Create table Employees ( ID int primary key identity, FirstName nvarchar(50), LastName nvarchar(50), Gender nvarchar(50), Salary int ) GO Insert into Employees values ('Ben', 'Hoskins', 'Male', 70000) Insert into Employees values ('Mark', 'Hastings', 'Male', 60000) Insert into Employees values ('Steve', 'Pound', 'Male', 45000) Insert into Employees values ('Ben', 'Hoskins', 'Male', 70000) Insert into Employees values ('Philip', 'Hastings', 'Male', 45000) Insert into Employees values ('Mary', 'Lambeth', 'Female', 30000) Insert into Employees values ('Valarie', 'Vikings', 'Female', 35000) Insert into Employees values ('John', 'Stanmore', 'Male', 80000) GO To find the highest salary it is straight forward. We can simply use the Max() function as shown below. Select Max(Salary) from Employees To get the second highest salary use a sub query along with Max() function as shown below. Select Max(Salary) from Employees where Salary [ (Select Max(Salary) from Employees) To find nth highest salary using Sub-Query SELECT TOP 1 SALARY FROM ( SELECT DISTINCT TOP N SALARY FROM EMPLOYEES ORDER BY SALARY DESC ) RESULT ORDER BY SALARY To find nth highest salary using CTE WITH RESULT AS ( SELECT SALARY, DENSE_RANK() OVER (ORDER BY SALARY DESC) AS DENSERANK FROM EMPLOYEES ) SELECT TOP 1 SALARY FROM RESULT WHERE DENSERANK = N To find 2nd highest salary we can use any of the above queries. Simple replace N with 2. Similarly, to find 3rd highest salary, simple replace N with 3. Please Note: On many of the websites, you may have seen that, the following query can be used to get the nth highest salary. The below query will only work if there are no duplicates. WITH RESULT AS ( SELECT SALARY, ROW_NUMBER() OVER (ORDER BY SALARY DESC) AS ROWNUMBER FROM EMPLOYEES ) SELECT SALARY FROM RESULT WHERE ROWNUMBER = 3

Part 2 SQL query to get organization hierarchy
![Beginner to T-SQL [Full Course]](https://i.ytimg.com/vi/cACat4KNncg/hqdefault.jpg?sqp=-oaymwEjCNACELwBSFryq4qpAxUIARUAAAAAGAElAADIQj0AgKJDeAE=&rs=AOn4CLA4o6xA3UzwmxwP9P-enFU9sgxi6Q)
Beginner to T-SQL [Full Course]

SQL Server Backup Failed? Error 5 & Error 3 Explained | Real-Time Demo |

Part 3 How does a recursive CTE work

The 25 SQL Questions You MUST Know for Data Analyst Interviews

Learn SQL Beginner to Advanced in Under 4 Hours

Find Nth Highest Salary in SQL | 5 Different Ways | Most Important SQL Interview Question

SQL Server Interview Questions and Answers | SQL Interview Questions

7 Simple Tricks to Instantly Make Your SQL Queries Better

Group by in sql server - Part 11

Trump Sells UFC Coins as Iran Strikes & Melania Pushes AI in a Speech Worthy of AI | The Daily Show

Learn SQL in 1 Hour - SQL Basics for Beginners
![SQL Course for Beginners [Full Course]](https://i.ytimg.com/vi/7S_tz1z_5bA/hqdefault.jpg?sqp=-oaymwEjCNACELwBSFryq4qpAxUIARUAAAAAGAElAADIQj0AgKJDeAE=&rs=AOn4CLCAEolqW9nvnTsvv0q31O_tNsNdIw)
SQL Course for Beginners [Full Course]

SQL Tutorial for Beginners

Top SQL Queries for Interviews Questions and Answers | SQL Training | Intellipaat

Test Your SQL Skills With These Real Interview Questions!

Mexiko – Südafrika Highlights | Gruppe A, FIFA WM 2026 | sportstudio

Part 6 Transform rows into columns in sql server

