Second Highest Salary
Updated
Problem statement
The employees table lists the staff of one bank branch, one row per employee, with each person's yearly salary. Several employees can earn exactly the same amount.
Write a query that returns the second highest salary in the table. Salaries are compared as values, so equal salaries count once: if the two best-paid employees both earn the top amount, the answer is the next smaller amount, not the top amount again.
Return exactly one row with one column, second_highest_salary. When the table has fewer than two different salaries, return that one row with NULL (None in Pandas).
Table schema
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 of the branch.
| Column | Type | Nullable | Description |
|---|---|---|---|
| employee_idPK | Integer | No | Unique employee ID. |
| employee_name | Text | No | The employee's name. |
| salary | Integer | No | Yearly salary. |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| second_highest_salary | Integer | Yes | — |
Row order: any order is accepted. Numeric tolerance: 0.
Constraints
- The
employeestable has between1and1000rows. employee_idvalues are unique, with1 <= employee_id <= 100000.employee_namehas 1 to 40 characters.1 <= salary <= 1000000
More Bank of America Onsite Interview questions
- Centered Star PyramidONSITE INTERVIEW · Seen Nov 2025
- Employees Without a ManagerONSITE INTERVIEW · Seen Nov 2025
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2025
- N-th Fibonacci NumberONSITE INTERVIEW · Seen Nov 2025
- Reverse Each Word in a SentenceONSITE INTERVIEW · Seen Nov 2025
- Three Numbers That Add Up to a TargetONSITE INTERVIEW · Seen Apr 2025
- Duplicate RowsONSITE INTERVIEW · Seen Oct 2023
- Factorial of a NumberONSITE INTERVIEW · Seen Oct 2023
- Palindrome String CheckONSITE INTERVIEW · Seen Sep 2023
- Second Largest Element in an ArrayONSITE INTERVIEW · Seen Jun 2023
Similar questions at other companies
- Delete Duplicate Employee RecordsInfosys · ONSITE INTERVIEWInfosys interview questions
- Records Created or Updated in a Time WindowPelatro · ONSITE INTERVIEW
- Top Ten Employee SalariesSolytics Partners · ONSITE INTERVIEW
- Latest New JobSphere · ONSITE INTERVIEW
- Employees Whose Manager Left the CompanyZS · ONSITE INTERVIEWZS interview questions
- Employees Above Average SalaryJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Retrieve Every Student RecordLSEG · ONSITE INTERVIEWLSEG interview questions
- Combine Winner and Loser NamesAmazon · ONSITE INTERVIEW
- Conditionally Insert or Update RecordsKlaviyo · ONSITE INTERVIEWKlaviyo interview questions
- Employees with Matching DepartmentsAMD · ONSITE INTERVIEWAMD interview questions