logo

Back to questions

Second Highest Salary [FAANG SQL Interview Question]

Medium

Imagine you're an HR analyst at a tech company tasked with analyzing employee salaries. Your manager is keen on understanding the pay distribution and asks you to determine the second highest salary among all employees.

It's possible that multiple employees may share the same second highest salary. In case of duplicate, display the salary only once.

Schema:

column_nametypedescription
employee_idintegerThe unique ID of the employee.
namestringThe name of the employee.
salaryintegerThe salary of the employee.
department_idintegerThe department ID of the employee.
manager_idintegerThe manager ID of the employee.

Example Input:

employee_idnamesalarydepartment_idmanager_id
1Emma Thompson380016
2Daniel Rodriguez223017
3Olivia Smith200018

Example Output:

second_highest_salary
2230

The output represents the second highest salary among all employees. In this case, the second highest salary is $2,230.

The dataset you are querying against may have different input & output - this is just an example!

PostgreSQL 14