0
0
SQLquery~20 mins

LEFT JOIN vs RIGHT JOIN decision in SQL - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Join Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Choosing between LEFT JOIN and RIGHT JOIN

You have two tables: Employees and Departments. You want to list all employees and their departments, including employees who are not assigned to any department.

Which JOIN type should you use?

AINNER JOIN Employees to Departments
BLEFT JOIN Employees to Departments
CFULL OUTER JOIN Employees to Departments
DRIGHT JOIN Employees to Departments
Attempts:
2 left
💡 Hint

Think about which table you want to keep all rows from.

query_result
intermediate
2:00remaining
Result of LEFT JOIN vs RIGHT JOIN

Given these tables:

Employees: (id, name)
1, Alice
2, Bob
3, Carol

Departments: (id, dept_name)
2, Sales
3, HR
4, IT

What is the result of this query?

SELECT Employees.name, Departments.dept_name
FROM Employees
LEFT JOIN Departments ON Employees.id = Departments.id;
A[{"name": "Alice", "dept_name": "Sales"}, {"name": "Bob", "dept_name": "HR"}, {"name": "Carol", "dept_name": "IT"}]
B[{"name": "Bob", "dept_name": "Sales"}, {"name": "Carol", "dept_name": "HR"}, {"name": null, "dept_name": "IT"}]
C[{"name": "Alice", "dept_name": null}, {"name": "Bob", "dept_name": null}, {"name": "Carol", "dept_name": null}]
D[{"name": "Alice", "dept_name": null}, {"name": "Bob", "dept_name": "Sales"}, {"name": "Carol", "dept_name": "HR"}]
Attempts:
2 left
💡 Hint

LEFT JOIN keeps all rows from Employees and matches Departments where IDs are equal.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in RIGHT JOIN query

Which option contains a syntax error in this RIGHT JOIN query?

SELECT e.name, d.dept_name
FROM Employees e
RIGHT JOIN Departments d ON e.id = d.id;
A;di.d = di.e NO d stnemtrapeD NIOJ THGIR e seeyolpmE MORF eman_tped.d ,eman.e TCELES
BSELECT e.name, d.dept_name FROM Employees e RIGHT JOIN Departments d ON e.id = d.id;
CSELECT e.name, d.dept_name FROM Employees e RIGHT JOIN Departments d WHERE e.id = d.id;
DSELECT e.name, d.dept_name FROM Employees e RIGHT JOIN Departments d ON e.id = d.id
Attempts:
2 left
💡 Hint

Check the placement of the ON clause in JOIN syntax.

optimization
advanced
2:00remaining
Optimizing a query with LEFT JOIN vs RIGHT JOIN

You want to optimize a query that lists all departments and their employees, including departments with no employees. Which join is generally more efficient?

ALEFT JOIN Departments to Employees
BINNER JOIN Departments to Employees
CRIGHT JOIN Employees to Departments
DFULL OUTER JOIN Departments to Employees
Attempts:
2 left
💡 Hint

Think about which table you want to keep all rows from and typical indexing.

🔧 Debug
expert
3:00remaining
Debugging unexpected NULLs in RIGHT JOIN result

You run this query:

SELECT e.name, d.dept_name
FROM Employees e
RIGHT JOIN Departments d ON e.id = d.id;

But you see NULLs in e.name for some rows unexpectedly. What is the most likely cause?

AThere are departments with no matching employee IDs
BThe JOIN condition is incorrect and should be e.dept_id = d.id
CRIGHT JOIN always produces NULLs in the left table columns
DEmployees table has NULL values in the id column
Attempts:
2 left
💡 Hint

Think about what RIGHT JOIN does and when NULLs appear.