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 matched rows from the right table. If there is no match, the result is NULL on the right side.
Click to reveal answer
beginner
In a LEFT JOIN, what happens if there is no matching row in the right table?
The query still returns the row from the left table, but the columns from the right table will have NULL values.
Click to reveal answer
beginner
Write a simple SQL LEFT JOIN query to get all customers and their orders, including customers with no orders.
SELECT customers.id, customers.name, orders.id AS order_id FROM customers LEFT JOIN orders ON customers.id = orders.customer_id;
Click to reveal answer
intermediate
Why is LEFT JOIN useful when you want to preserve all rows from the left table?
Because it ensures no rows from the left table are lost, even if there are no matching rows in the right table. This helps to keep all original data from the left side.
Click to reveal answer
beginner
What is the difference between INNER JOIN and LEFT JOIN?
INNER JOIN returns only rows with matching keys in both tables. LEFT JOIN returns all rows from the left table, with matching rows from the right or NULL if no match.
Click to reveal answer
What will a LEFT JOIN return if the right table has no matching rows?
AAll rows from the left table with NULLs for right table columns
BNo rows at all
COnly rows with matches in both tables
DOnly rows from the right table
✗ Incorrect
LEFT JOIN keeps all rows from the left table and fills right table columns with NULL if no match.
Which SQL keyword is used to keep all rows from the left table regardless of matches?
ALEFT JOIN
BRIGHT JOIN
CFULL JOIN
DINNER JOIN
✗ Incorrect
LEFT JOIN returns all rows from the left table and matched rows from the right.
If you want to find customers without orders, which join helps you?
ASELF JOIN
BINNER JOIN
CCROSS JOIN
DLEFT JOIN
✗ Incorrect
LEFT JOIN includes all customers, even those without orders, showing NULL for missing orders.
In a LEFT JOIN, what does a NULL in the right table columns mean?
AThere is a matching row
BThe right table is empty
CNo matching row in the right table
DThe left table has NULL values
✗ Incorrect
NULL in right table columns means no matching row was found for that left table row.
Which join type would exclude rows from the left table if no match is found?
ALEFT JOIN
BINNER JOIN
CRIGHT JOIN
DFULL JOIN
✗ Incorrect
INNER JOIN returns only rows with matches in both tables, excluding unmatched left rows.
Explain how a LEFT JOIN preserves all rows from the left table and what happens when there is no match in the right table.
Think about what happens to unmatched rows on the right side.
You got /3 concepts.
Write a simple SQL query using LEFT JOIN to list all employees and their departments, including employees without a department.
Use employee table as left and department table as right.
You got /4 concepts.
Practice
(1/5)
1. What does a LEFT JOIN do in SQL?
easy
A. Deletes rows from the left table that have no match in the right table.
B. Keeps only rows that have matches in both tables.
C. Keeps all rows from the right table and adds matching rows from the left table.
D. Keeps all rows from the left table and adds matching rows from the right table or NULL if no match.
Solution
Step 1: Understand LEFT JOIN behavior
A LEFT JOIN returns all rows from the left table regardless of matches in the right table.
Step 2: Check what happens with unmatched rows
If there is no matching row in the right table, the result shows NULL for right table columns.
Final Answer:
Keeps all rows from the left table and adds matching rows from the right table or NULL if no match. -> Option D
Quick Check:
LEFT JOIN = all left rows kept [OK]
Hint: Remember: LEFT JOIN keeps all left rows, fills right with NULL if no match [OK]
Common Mistakes:
Confusing LEFT JOIN with INNER JOIN
Thinking it keeps all right table rows
Assuming unmatched rows are dropped
2. Which of the following is the correct syntax for a LEFT JOIN in SQL?
easy
A. SELECT * FROM table1 LEFT ON JOIN table2 WHERE table1.id = table2.id;
B. SELECT * FROM table1 JOIN LEFT table2 ON table1.id = table2.id;
C. SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id;
D. SELECT * FROM table1 LEFT JOIN table2 WHERE table1.id = table2.id;
Solution
Step 1: Review correct LEFT JOIN syntax
The correct syntax is: SELECT columns FROM left_table LEFT JOIN right_table ON condition;
Step 2: Identify syntax errors in other options
Options A, B, and D misuse keywords or omit ON clause, causing syntax errors.
Final Answer:
SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id; -> Option C
Quick Check:
LEFT JOIN syntax = SELECT ... LEFT JOIN ... ON ... [OK]
Hint: LEFT JOIN always uses ON to specify join condition [OK]
Common Mistakes:
Swapping JOIN and LEFT keywords
Using WHERE instead of ON for join condition
Omitting ON clause
3. Given these tables:
Employees id | name 1 | Alice 2 | Bob 3 | Carol
Sales emp_id | amount 1 | 100 3 | 200
What is the result of: SELECT Employees.name, Sales.amount FROM Employees LEFT JOIN Sales ON Employees.id = Sales.emp_id;
medium
A. [('Alice', 100), ('Bob', 0), ('Carol', 200)]
B. [('Alice', 100), ('Bob', NULL), ('Carol', 200)]
C. [('Alice', 100), ('Carol', 200)]
D. [('Bob', NULL)]
Solution
Step 1: Match Employees with Sales using LEFT JOIN
All Employees rows appear. For matching emp_id in Sales, amount is shown; else NULL.
Step 2: Map each employee to sales amount or NULL
Alice (id=1) matches 100, Bob (id=2) no match so NULL, Carol (id=3) matches 200.
Final Answer:
[('Alice', 100), ('Bob', NULL), ('Carol', 200)] -> Option B
Quick Check:
LEFT JOIN keeps all left rows with NULL for no match [OK]
Hint: LEFT JOIN shows NULL for unmatched right rows, not zero [OK]
Common Mistakes:
Replacing NULL with zero
Omitting unmatched rows
Confusing LEFT JOIN with INNER JOIN
4. Consider this query:
SELECT a.id, b.value FROM A LEFT JOIN B ON a.id = b.a_id WHERE b.value > 10;
What is the problem with this query if you want to keep all rows from A?
medium
A. The WHERE clause filters out rows where b.value is NULL, losing some left rows.
B. The ON clause is missing a join condition.
C. LEFT JOIN should be replaced with INNER JOIN for correct results.
D. The SELECT statement is missing table aliases.
Solution
Step 1: Understand effect of WHERE on LEFT JOIN
WHERE filters after join, so rows with NULL b.value are removed, losing left rows.
Step 2: Identify how to fix to keep all left rows
Move condition to ON clause or use WHERE b.value > 10 OR b.value IS NULL to preserve unmatched rows.
Final Answer:
The WHERE clause filters out rows where b.value is NULL, losing some left rows. -> Option A
Quick Check:
WHERE after LEFT JOIN can remove unmatched rows [OK]
Hint: Put filters on right table in ON, not WHERE, to keep all left rows [OK]