Practice mode DBMS and SQL

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.