TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst · 76.7K subscribers
Post #2829 1.84K
SQL Interview Series — Part 1

Hi guys, let's start a SQL interview series covering frequently asked and important SQL interview questions.

Each part will cover 1 practical interview question with:

✅ Problem statement

✅ SQL solution

✅ Approach

✅ Interview tip

📌 Question 1: Find the Second Highest Salary

Suppose you have an Employee table:

Employee

• employee_id

• employee_name

• salary

Example data:

employee_id| employee_name| salary

1| Amit| 50000

2| Rahul| 80000

3| Priya| 70000

4| Neha| 90000

5| Raj| 80000

❓ Find the second-highest salary from the Employee table.

💡 Approach

First, we need to identify the highest salary.

Then, we need the highest salary that is less than the maximum salary.

One simple approach is to use a subquery:
SELECT MAX(salary) AS second_highest_salary
FROM Employee
WHERE salary < (
    SELECT MAX(salary)
    FROM Employee
);

Output:

second_highest_salary

80000

🔎 Why does this work?

The inner query:
SELECT MAX(salary)
FROM Employee;

returns:

90000

Then the outer query considers only salaries below 90000:

50000

70000

80000

80000

Finally, MAX() returns:

80000

⚠️ Important Interview Point

If the question asks for the second-highest DISTINCT salary, this approach works because duplicate salaries are naturally treated as one value.

For example:

90000

80000

80000

70000

The second-highest distinct salary is still 80000.

💯 Double Tap ❤️ For Part-2
  • ❤ 14
More from @sqlanalyst
  1. Sep 29, 2026SQL Interview Series — Part 2 📌 Question 2: Find Duplicate Records Suppose you have an Em…
  2. Sep 29, 2026𝗙𝗥𝗘𝗘 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 𝗧𝗼 𝗟𝗲𝗮𝗿𝗻 𝗔𝗜 𝗶𝗻 𝟮𝟬𝟮𝟲🚀 ​ Explore 6 free resource…
  3. Sep 28, 2026🧠 Real-World SQL Scenario-Based Questions & Answers 1. Get the 2nd highest salary from th…
  4. Sep 28, 2026🎓 𝗛𝗔𝗥𝗩𝗔𝗥𝗗 𝗨𝗡𝗜𝗩𝗘𝗥𝗦𝗜𝗧𝗬 𝗙𝗥𝗘𝗘 𝗢𝗡𝗟𝗜𝗡𝗘 𝗖𝗢𝗨𝗥𝗦𝗘𝗦 😍 Dreaming of…
  5. Sep 27, 2026Data Analytics Roadmap | |-- Fundamentals | |-- Mathematics | | |-- Descriptive Statistics…
  6. Sep 27, 2026𝗟𝗲𝘃𝗲𝗹 𝗨𝗽 𝗬𝗼𝘂𝗿 𝗦𝗸𝗶𝗹𝗹𝘀 𝘄𝗶𝘁𝗵 𝗧𝗵𝗲𝘀𝗲 𝗚𝗮𝗺𝗲-𝗖𝗵𝗮𝗻𝗴𝗶𝗻𝗴 𝗖𝗼𝘂…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →