Write an SQL query that displays each employee’s name along with their manager’s name using a self‑join on the Employee table.
1Times asked
Jul 2026Last seen
Jul 2026First seen
💡 Model Answer
Assuming the Employee table has columns emp_id, emp_name, and manager_id (which references emp_id of the manager), you can join the table to itself:
sql
SELECT e.emp_name AS employee_name,
m.emp_name AS manager_name
FROM Employee e
LEFT JOIN Employee m
ON e.manager_id = m.emp_id;The LEFT JOIN ensures that employees without a manager (e.g., the CEO) still appear with a NULL manager_name. If you want to exclude those rows, use an INNER JOIN instead. The query runs in O(n) time, where n is the number of employees, because it performs a single hash or merge join on the primary key.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500