Second-Highest Distinct Salary
Updated
Problem statement
The table employees contains one row per employee with an integer salary. Find the second-highest distinct salary.
Return exactly one row with the column second_highest_salary. If fewer than two distinct salaries exist, return NULL in that row.
Table: employees
| Column | Type | Meaning |
|---|---|---|
employee_id | integer | Unique employee identifier |
salary | integer | Employee salary |
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
employees
One row per employee.
| Column | Type | Nullable | Description |
|---|---|---|---|
| employee_idPK | Integer | No | — |
| salary | Integer | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| second_highest_salary | Integer | Yes | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- The table may be empty.
employee_idis unique and non-null.salaryis non-null and is between-10^9and10^9.- Equal salaries share a rank.
More Infosys interview questions
- Swap Two Gender ValuesPHONE SCREEN · Seen Oct 2026
- At Most K Jumps with Quadratic Transition CostOA · Seen Nov 2026
- Hiking Club Fastest PaceOA · Seen Nov 2026
- Lowest Common Ancestor with a Changing RootOA · Seen Nov 2026
- Minimum Coins for a TargetONSITE INTERVIEW · Seen Nov 2026
- Minimum Leaf Path Sum over All RootsOA · Seen Nov 2026
- Split Array to Minimize the Largest SumOA · Seen Nov 2026
- Cherry PickupOA · Seen Nov 2026
- Delete Duplicate Employee RecordsONSITE INTERVIEW · Seen Nov 2026
- Find Duplicate Employee RecordsONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Second Highest SalaryPaytm · PHONE SCREENPaytm interview questions
- Employees Who Earn More Than Their ManagersNykaa · PHONE SCREENNykaa interview questions
- Employees Who Joined More Than a Week AgoNewgen Software · PHONE SCREEN
- Departments Without EmployeesDell Technologies · PHONE SCREENDell Technologies interview questions
- Second-Highest Distinct SalaryChubb · PHONE SCREENChubb interview questions
- Find Rows Common to Two TablesSalesforce · PHONE SCREENSalesforce interview questions
- Count Records Present in A but Not BCapital One · PHONE SCREENCapital One interview questions
- Customer Order Count Distribution by CountryApple · PHONE SCREENApple interview questions
- Employees Earning More Than Their ManagerMygate · PHONE SCREENMygate interview questions
- Classify Tree Nodes with SQLOracle · PHONE SCREENOracle interview questions