ZS Associates Interview Question

SQL queries to find 2nd highest salary from the table

Interview Answer

Anonymous

Jan 14, 2021

Using normal group by along with Sub Query: Select the Max( Salary) from Employee where Salary NOT in (select Max(Salary) from Employee) Using Window Function: You can use Rank function to rank the salaries in descending and then use CTE to filter the one with Rank = 2 (This can work for any Nth Rank)

2