0
0
SQLquery~10 mins

LEFT JOIN preserving all left rows 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 columns from the left table and join with the right table.

SQL
SELECT * FROM employees [1] departments ON employees.department_id = departments.id;
Drag options to blanks, or click blank then click option'
AINNER JOIN
BLEFT JOIN
CRIGHT JOIN
DFULL JOIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using INNER JOIN which excludes unmatched rows from the left table.
Using RIGHT JOIN which keeps all rows from the right table instead.
2fill in blank
medium

Complete the code to select employee names and their department names, preserving all employees even if they have no department.

SQL
SELECT employees.name, [1].name AS department_name FROM employees LEFT JOIN departments ON employees.department_id = departments.id;
Drag options to blanks, or click blank then click option'
Aprojects
Bemployees
Cmanagers
Ddepartments
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting employees.name as department_name by mistake.
Selecting a table that is not joined in the query.
3fill in blank
hard

Fix the error in the join condition to correctly join employees with departments preserving all employees.

SQL
SELECT employees.name, departments.name FROM employees LEFT JOIN departments ON employees.[1] = departments.id;
Drag options to blanks, or click blank then click option'
Adepartment_id
Bmanager_id
Cdept_id
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using employees.id which is the employee's own id, not the department reference.
Using a column that does not exist in employees.
4fill in blank
hard

Fill both blanks to select employee names and their department names, showing 'No Department' if the department is missing.

SQL
SELECT employees.name, COALESCE(departments.[1], [2]) AS department_name FROM employees LEFT JOIN departments ON employees.department_id = departments.id;
Drag options to blanks, or click blank then click option'
Aname
B'No Department'
C'Unknown'
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name from departments.
Not providing a string literal for the default value.
5fill in blank
hard

Fill all three blanks to count employees per department, including departments with zero employees.

SQL
SELECT departments.[1], COUNT(employees.[2]) AS employee_count FROM departments LEFT JOIN employees ON employees.[3] = departments.id GROUP BY departments.name;
Drag options to blanks, or click blank then click option'
Aname
Bid
Cdepartment_id
Attempts:
3 left
💡 Hint
Common Mistakes
Counting department id instead of employee id.
Joining on wrong columns causing incorrect counts.