Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

60 Days of Data Days! Live and on-demand sessions, challenges, study groups and more! And it's all FREE!. Join now. Learn more

Reply
powerbidev123
Solution Sage
Solution Sage

Need SQl help

Hi All

 

I need help with a SQL problem as desc below

 

Find the second highest salary from an Employee table without using LIMIT, TOP, or window functions.

1 ACCEPTED SOLUTION
ShivekMaharaj
Impactful Individual
Impactful Individual

Hi @powerbidev123 ,

 

You can use a subquery to find the maximum salary that is lower than the overall maximum salary:

SELECT MAX(salary) AS second_highest_salary
FROM Employee
WHERE salary < (
    SELECT MAX(salary)
    FROM Employee
);

 

The inner query finds the highest salary. The outer query then finds the highest salary below that value, which gives you the second-highest distinct salary.

 

This also handles duplicate highest salaries correctly.

View solution in original post

1 REPLY 1
ShivekMaharaj
Impactful Individual
Impactful Individual

Hi @powerbidev123 ,

 

You can use a subquery to find the maximum salary that is lower than the overall maximum salary:

SELECT MAX(salary) AS second_highest_salary
FROM Employee
WHERE salary < (
    SELECT MAX(salary)
    FROM Employee
);

 

The inner query finds the highest salary. The outer query then finds the highest salary below that value, which gives you the second-highest distinct salary.

 

This also handles duplicate highest salaries correctly.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Fabric Update Carousel

Fabric Monthly Update - July 2026

Check out the July 2026 Fabric update to learn about new features.

Top Solution Authors