FastPrepSecond-Highest Distinct Salary

Second-Highest Distinct Salary

Infosys logoInfosys● EasyFULLTIMEPHONE SCREEN

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

ColumnTypeMeaning
employee_idintegerUnique employee identifier
salaryintegerEmployee 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.

ColumnTypeNullableDescription
employee_idPKIntegerNo—
salaryIntegerNo—

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
second_highest_salaryIntegerYes—

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • The table may be empty.
  • employee_id is unique and non-null.
  • salary is non-null and is between -10^9 and 10^9.
  • Equal salaries share a rank.

More Infosys problems

See Infosys hiring insights