๐ง SQL Interview Question (Self Join + Salary Comparison)
๐
employees(emp_id, manager_id, salary)
โ Ques :
๐ Find employees whose salary is higher than their managerโs salary.
๐งฉ How Interviewers Expect You to Think
โข Understand hierarchical relationships ๐ฅ
โข Use self join on same table
โข Compare values across related rows
โข Handle NULL manager cases
๐ก SQL Solution
SELECT
e.emp_id,
e.salary AS emp_salary,
m.salary AS manager_salary
FROM employees e
JOIN employees m
ON e.manager_id = m.emp_id
WHERE e.salary > m.salary;
๐ฅ Why This Question Is Powerful
โข Tests self join concept deeply ๐ง
โข Real-world scenario in org hierarchy analysis
โข Checks ability to compare across rows
โข Frequently asked in interviews
โค๏ธ React if you want more real interview-level SQL questions ๐
Post #2125
2.58K
- โค 2
- ๐ 2