Question Description
Write a SQL query to get the second highest salary from the Employee table.
Question Approach
Question Tips
Question Analyze Procedure
N/A
Question Set Up and Solution Demo
Schema (MySQL v8.0)
CREATE TABLE Employee (
`Id` INTEGER,
`Salary` INTEGER
);
INSERT INTO Employee
(`Id`, `Salary`)
VALUES
('1', '100'),
('2', '200'),
('3', '300');
CREATE TABLE Result (
`SecondHighestSalary` INTEGER,
`ignore` VARCHAR(1)
);
INSERT INTO Result
(`SecondHighestSalary`, `ignore`)
VALUES
('200', '_');
Query #1
SELECT
MAX(Salary) AS SecondHighestSalary
FROM
Employee
WHERE Salary NOT IN (
SELECT
MAX(Salary)
FROM Employee
);
SecondHighestSalary |
---|
200 |