Table Emp(id, name, mgr_id) has rows (1,’Ayesha’,NULL), (2,’Bilal’,1), (3,’Hina’,1), (4,’Kamran’,2). SELECT e.name FROM Emp e JOIN Emp m ON e.mgr_id = m.id WHERE m.name = ‘Ayesha’ ORDER BY e.name; What is returned?
Correct answer B. Bilal, Hina
Explanation
This is a self join: the same table appears twice under aliases e (employee) and m (manager). Each employee row is joined with the row of its manager, and the WHERE clause keeps pairs whose manager is Ayesha. Bilal and Hina have mgr_id 1. Kamran reports to Bilal, not directly to Ayesha, so a single self join does not reach him.
Answer checked How we write and check questions
Discussion