0
0
MySQLquery~10 mins

Self JOIN in MySQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select employee names and their managers' names using a self join.

MySQL
SELECT e.name AS employee, m.name AS manager FROM employees e JOIN employees m ON e.manager_id = [1].id;
Drag options to blanks, or click blank then click option'
Am
Be
Cemployees
Dmanagers
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong alias like 'e.id' instead of 'm.id'.
Using the table name instead of alias in the ON clause.
2fill in blank
medium

Complete the code to find employees who have the same manager.

MySQL
SELECT e1.name, e2.name FROM employees e1 JOIN employees e2 ON e1.[1] = e2.manager_id WHERE e1.id != e2.id;
Drag options to blanks, or click blank then click option'
Amanager_id
Bdepartment_id
Cname
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Joining on employee IDs instead of manager IDs.
Using the same alias on both sides of the join condition.
3fill in blank
hard

Fix the error in the self join query to correctly list employees and their managers.

MySQL
SELECT e.name, m.name FROM employees e JOIN employees m ON e.manager_id = [1] WHERE m.id = e.manager_id;
Drag options to blanks, or click blank then click option'
Ae.id
Bm.manager_id
Cm.id
De.manager_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using employee's own ID instead of manager's ID in the join.
Confusing the aliases in the ON clause.
4fill in blank
hard

Fill both blanks to select employees and their managers' names, including employees without managers.

MySQL
SELECT e.name AS employee, [1].name AS manager FROM employees e LEFT JOIN employees [2] ON e.manager_id = [2].id;
Drag options to blanks, or click blank then click option'
Am
Be
Dmanagers
Attempts:
3 left
💡 Hint
Common Mistakes
Using different aliases in SELECT and JOIN.
Using INNER JOIN instead of LEFT JOIN, missing employees without managers.
5fill in blank
hard

Fill all three blanks to find employees who are also managers of others.

MySQL
SELECT DISTINCT [1].name FROM employees [2] JOIN employees [3] ON [2].id = [3].manager_id;
Drag options to blanks, or click blank then click option'
Am
Be
Dmanagers
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up aliases for employees and managers.
Not using DISTINCT, causing duplicate manager names.