0
0
SQLquery~10 mins

Self join concept in SQL - 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 all employees and their managers using a self join.

SQL
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'
Aemployees
Bm
Ce
Dmanagers
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same alias for both tables causes confusion.
Joining on the wrong columns or missing the alias before the column.
2fill in blank
medium

Complete the code to find employees whose manager's name is 'Alice'.

SQL
SELECT e.name FROM employees e JOIN employees m ON e.manager_id = m.id WHERE m.name = [1];
Drag options to blanks, or click blank then click option'
A'Bob'
B'Manager'
C'Alice'
D'John'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string value.
Using the employee's name instead of the manager's name in the WHERE clause.
3fill in blank
hard

Fix the error in the code to correctly list employees and their managers.

SQL
SELECT e.name, m.name 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
Joining on the wrong column causing no results or errors.
Using the employee alias instead of the manager alias in the join condition.
4fill in blank
hard

Fill both blanks to select employees and their managers who work in the same department.

SQL
SELECT e.name, m.name FROM employees e JOIN employees m ON e.manager_id = m.id WHERE e.[1] = m.[2];
Drag options to blanks, or click blank then click option'
Adepartment_id
Bmanager_id
Cid
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using manager_id or id instead of department_id for the comparison.
Comparing employee's department_id with manager's name or other unrelated columns.
5fill in blank
hard

Fill all three blanks to create a query that lists employees, their managers, and the manager's department name.

SQL
SELECT e.name AS employee, m.name AS manager, d.[1] FROM employees e JOIN employees m ON e.[2] = m.[3] JOIN departments d ON m.department_id = d.id;
Drag options to blanks, or click blank then click option'
Adepartment_name
Bmanager_id
Cid
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column names for joins causing errors.
Selecting wrong columns from the departments table.