Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does a LEFT JOIN do in SQL?
A LEFT JOIN returns all rows from the left table and the matching rows from the right table. If there is no match, the result is NULL on the right side.
Click to reveal answer
beginner
What does a RIGHT JOIN do in SQL?
A RIGHT JOIN returns all rows from the right table and the matching rows from the left table. If there is no match, the result is NULL on the left side.
Click to reveal answer
intermediate
When should you use LEFT JOIN instead of RIGHT JOIN?
Use LEFT JOIN when you want to keep all rows from the first (left) table and add matching data from the second (right) table. It is often easier to read and understand.
Click to reveal answer
intermediate
Can a RIGHT JOIN be rewritten as a LEFT JOIN?
Yes. A RIGHT JOIN can be rewritten as a LEFT JOIN by swapping the order of the tables. This helps keep queries consistent and easier to read.
Click to reveal answer
beginner
Why might developers prefer LEFT JOIN over RIGHT JOIN?
Developers often prefer LEFT JOIN because it reads naturally from left to right, matching the order of tables in the query. This improves clarity and reduces confusion.
Click to reveal answer
What does a LEFT JOIN return?
AAll rows from both tables
BAll rows from the left table and matching rows from the right table
COnly matching rows from both tables
DAll rows from the right table and matching rows from the left table
✗ Incorrect
LEFT JOIN returns all rows from the left table and matching rows from the right table, filling with NULLs if no match.
How can you rewrite a RIGHT JOIN as a LEFT JOIN?
ASwap the order of the tables and use LEFT JOIN
BChange RIGHT JOIN to INNER JOIN
CUse FULL JOIN instead
DYou cannot rewrite RIGHT JOIN as LEFT JOIN
✗ Incorrect
RIGHT JOIN can be rewritten as LEFT JOIN by swapping the tables' order.
Which join is usually easier to read and understand?
ALEFT JOIN
BRIGHT JOIN
CFULL JOIN
DCROSS JOIN
✗ Incorrect
LEFT JOIN is often easier to read because it follows the natural left-to-right order.
If you want all rows from the right table regardless of matches, which join do you use?
ACROSS JOIN
BLEFT JOIN
CINNER JOIN
DRIGHT JOIN
✗ Incorrect
RIGHT JOIN returns all rows from the right table and matching rows from the left.
What happens to unmatched rows in the right table when using LEFT JOIN?
AThey are included with NULLs for left table columns
BThey are included with NULLs for right table columns
CThey are excluded
DThey cause an error
✗ Incorrect
LEFT JOIN excludes unmatched rows from the right table; only unmatched left table rows appear with NULLs on the right.
Explain the difference between LEFT JOIN and RIGHT JOIN in simple terms.
Think about which table's rows you want to keep fully.
You got /4 concepts.
Describe when and why you might choose LEFT JOIN over RIGHT JOIN in a query.
Consider readability and table order.
You got /4 concepts.
Practice
(1/5)
1. Which JOIN type keeps all rows from the first (left) table, even if there is no matching row in the second (right) table?
easy
A. RIGHT JOIN
B. INNER JOIN
C. LEFT JOIN
D. FULL JOIN
Solution
Step 1: Understand LEFT JOIN behavior
LEFT JOIN returns all rows from the first table and matching rows from the second table. If no match, NULLs appear for second table columns.
Step 2: Compare with RIGHT JOIN
RIGHT JOIN keeps all rows from the second table, not the first. INNER JOIN only returns matching rows. FULL JOIN returns all rows from both tables.
Final Answer:
LEFT JOIN -> Option C
Quick Check:
LEFT JOIN keeps all left table rows [OK]
Hint: LEFT JOIN keeps all from first table, RIGHT JOIN from second [OK]
Common Mistakes:
Confusing LEFT JOIN with RIGHT JOIN
Thinking INNER JOIN keeps unmatched rows
Assuming FULL JOIN keeps only one table's rows
2. Which of the following is the correct syntax to perform a RIGHT JOIN between tables Employees and Departments on Employees.DeptID = Departments.ID?
easy
A. SELECT * FROM Employees RIGHT JOIN Departments ON Employees.DeptID = Departments.ID;
B. SELECT * FROM Employees LEFT JOIN Departments ON Employees.DeptID = Departments.ID;
C. SELECT * FROM Employees RIGHT JOIN Departments WHERE Employees.DeptID = Departments.ID;
D. SELECT * FROM Employees JOIN Departments ON Employees.DeptID = Departments.ID;
Solution
Step 1: Check JOIN syntax correctness
RIGHT JOIN requires ON clause to specify join condition. SELECT * FROM Employees RIGHT JOIN Departments ON Employees.DeptID = Departments.ID; uses correct syntax with ON clause.
Step 2: Identify errors in other options
SELECT * FROM Employees LEFT JOIN Departments ON Employees.DeptID = Departments.ID; uses LEFT JOIN, not RIGHT JOIN. SELECT * FROM Employees RIGHT JOIN Departments WHERE Employees.DeptID = Departments.ID; uses WHERE instead of ON, which is incorrect for JOIN condition. SELECT * FROM Employees JOIN Departments ON Employees.DeptID = Departments.ID; uses JOIN without specifying LEFT or RIGHT, defaults to INNER JOIN.
Final Answer:
SELECT * FROM Employees RIGHT JOIN Departments ON Employees.DeptID = Departments.ID; -> Option A
Quick Check:
RIGHT JOIN needs ON clause [OK]
Hint: RIGHT JOIN syntax requires ON, not WHERE [OK]
Common Mistakes:
Using WHERE instead of ON for join condition
Confusing LEFT JOIN with RIGHT JOIN syntax
Omitting JOIN type defaults to INNER JOIN
3. Given tables Authors and Books, what will be the result of this query?
SELECT Authors.Name, Books.Title FROM Authors LEFT JOIN Books ON Authors.ID = Books.AuthorID;
Assuming Authors has 3 rows and Books has 2 rows, with one author having no books, what will the output include?
medium
A. Only authors who have books, excluding authors without books
B. All 3 authors with their book titles; NULL for authors without books
C. All books with their authors; NULL for books without authors
D. All authors and all books, matched and unmatched
Solution
Step 1: Understand LEFT JOIN output
LEFT JOIN keeps all rows from Authors (left table). For authors without matching books, Books.Title will be NULL.
Step 2: Analyze given data
Authors has 3 rows, Books has 2 rows. One author has no books, so that author appears with NULL for book title.
Final Answer:
All 3 authors with their book titles; NULL for authors without books -> Option B
Quick Check:
LEFT JOIN keeps all left rows, fills NULLs for no match [OK]
Hint: LEFT JOIN keeps all left rows, unmatched right columns are NULL [OK]
Common Mistakes:
Thinking unmatched left rows are excluded
Confusing LEFT JOIN with INNER JOIN
Assuming unmatched right rows appear in LEFT JOIN
4. You wrote this query but it returns fewer rows than expected:
SELECT * FROM Orders RIGHT JOIN Customers ON Orders.CustomerID = Customers.ID;
What is the likely mistake?
medium
A. Using ON instead of WHERE for join condition
B. Missing WHERE clause to filter rows
C. Not specifying table aliases
D. Using RIGHT JOIN instead of LEFT JOIN when Orders is the main table
Solution
Step 1: Identify which table's rows to keep
If Orders is the main table and you want all its rows, LEFT JOIN should be used, not RIGHT JOIN.
Step 2: Understand RIGHT JOIN effect
RIGHT JOIN keeps all rows from Customers (right table), so if Orders has rows without matching Customers, those rows are excluded.
Final Answer:
Using RIGHT JOIN instead of LEFT JOIN when Orders is the main table -> Option D
Quick Check:
Use LEFT JOIN to keep all left table rows [OK]
Hint: Use LEFT JOIN to keep all rows from first table [OK]
Common Mistakes:
Confusing LEFT and RIGHT JOIN roles
Expecting RIGHT JOIN to keep left table rows
Ignoring join direction impact on row count
5. You have two tables: Students (left) and Enrollments (right). You want a list of all students, including those not enrolled in any course, showing NULL for missing enrollment data. Which query is best and why?
Option A: SELECT * FROM Students LEFT JOIN Enrollments ON Students.ID = Enrollments.StudentID; Option B: SELECT * FROM Enrollments RIGHT JOIN Students ON Students.ID = Enrollments.StudentID;
hard
A. Option A, because LEFT JOIN keeps all students and matches enrollments
B. Option B, because RIGHT JOIN keeps all enrollments and matches students
C. Option A, but it excludes students without enrollments
D. Option B, but it excludes students without enrollments
Solution
Step 1: Identify which table's rows to keep
You want all students, even those without enrollments, so keep all rows from Students (left table).
Step 2: Choose JOIN type accordingly
LEFT JOIN keeps all rows from Students and matches enrollments or shows NULL if none. RIGHT JOIN would keep all enrollments, not all students.
Final Answer:
Option A, because LEFT JOIN keeps all students and matches enrollments -> Option A
Quick Check:
LEFT JOIN keeps all left table rows [OK]
Hint: Keep main table first, use LEFT JOIN to keep all its rows [OK]
Common Mistakes:
Using RIGHT JOIN but expecting all left table rows