Second Highest Salary - Sql - Easy - LeetCode
💻 coding

Second Highest Salary - Sql - Easy - LeetCode

1 min read 96 words
1 min read
ShareWhatsAppPost on X
  • 1The SQL query retrieves the second highest salary from the Employee table.
  • 2If no second highest salary exists, the query returns null.
  • 3The query uses a subquery to find the maximum salary less than the highest salary.

AI-generated summary · May not capture all nuances

Key Insight
AskGif

"The SQL query retrieves the second highest salary from the Employee table."

Second Highest Salary - Sql - Easy - LeetCode

Write a SQL query to get the second highest salary from the Employee table.

+----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+ For example, given the above Employee table, the query should return 200 as the second highest salary. If there is no second highest salary, then the query should return null.

+---------------------+ | SecondHighestSalary | +---------------------+ | 200 | +---------------------+

# Write your MySQL query statement below
Select Max(Salary) as SecondHighestSalary from Employee Where Salary < (Select Max(Salary) from Employee);

Enjoyed this article?

Share it with someone who'd find it useful.

ShareWhatsAppPost on X

sumitc91

Published on 16 October 2020 · 1 min read · 96 words

Part of AskGif Blog · coding

You might also like

Second Highest Salary - Sql - Easy - LeetCode | AskGif Blog