Day 18 — Second Highest Salary

100 Days to Amazon

Akshay Ravindran

--

100 Days to Amazon — Day Second Highest Salary

Photo by Sharon McCutcheon on Unsplash

Out of Free Stories? Here is my Friend Link.

Introduction

Hey Guys, Today is Day 18 of the challenge that I took. Wherein I will be solving every day for 100 days the programming questions that have been asked in previous interviews.

Today, We are going to look into an SQL query which had been asked in an Amazon interview.

All these problems are taken from the following e-book. 🎓

This is completely free 🆓 if you have an amazon kindle subscription.

This e-book contains 100 coding problems that have been asked in top tech interview questions. It also has a guide to solving all the problems in 200+ ways. These problems I assure you has been asked in previous interviews.

You have to decide whether you want to go unprepared for a tech interview or go ahead and quick search for this guide to solve the 100 problems.

Begin Your ascent to greatness🚀

Note : this e-book only contains the links to the solutions.

Day 18 — Second Highest Salary🏁

AIM🏹

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

Example

+----+--------+
| 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 |
+---------------------+

Code👇

--

--

Akshay Ravindran

Code -> Understand-> Repeat is my motto. I am a Data Engineer who writes about everything related to Data Science and Interview Preparation for SDE.