Second Highest Salary
Updated
Problem statement
The employee table has one row per employee: a unique id and an integer salary.
Write a query that returns the second highest distinct salary. Employees with the same salary count as one salary value. Return exactly one row with one column named second_highest_salary. If there are fewer than two distinct salaries, that row holds NULL.
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.
employee
One row per employee.
| Column | Type | Nullable | Description |
|---|---|---|---|
| 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
idis a unique integer between1and10^9.0 <= salary <= 10^6, and no value is null.- The table has at most
1000rows and may be empty.
More Paytm interview questions
- Nth Highest SalaryPHONE SCREEN · Seen Nov 2026
- Jump GamePHONE SCREEN · Seen Nov 2026
- LRU Cache with Expiring EntriesPHONE SCREEN · Seen Sep 2026
- Detect a Linked-List CycleONSITE INTERVIEW · Seen Sep 2026
- Find First and Last Position in Sorted ArrayONSITE INTERVIEW · Seen Sep 2026
- Minimum Coins for a TargetONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- 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
- Swap Two Gender ValuesInfosys · PHONE SCREENInfosys 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