Skip to content
Onsite

Second highest salary

EasyP1Coding

Table employee:

ColumnType
idint (primary key)
salaryint

Write a query that returns the second highest distinct salary as a single column named second_highest_salary. If there is no second highest salary, return one row with NULL.

Schema

CREATE TABLE employee (
  id int PRIMARY KEY,
  salary int NOT NULL
);

Example 1

Input
employee: (1, 100), (2, 200), (3, 300)
Output
second_highest_salary: 200

Example 2

Input
employee: (1, 100)
Output
second_highest_salary: NULL

Constraints

  • PostgreSQL dialect.
  • Salaries can repeat; duplicates count once.

Hints

PostgreSQL
Run checks the 2 visible tests, Submit all 5.