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 is an outer join in SQL?
An outer join returns all rows from one table and the matching rows from another table. If there is no match, it still shows the row with NULLs for the other table's columns.
Click to reveal answer
beginner
Why do we need outer joins instead of just inner joins?
Because inner joins only show rows with matches in both tables. Outer joins let us see rows even if there is no match, helping us find missing or unmatched data.
Click to reveal answer
intermediate
What are the types of outer joins?
There are three types: LEFT OUTER JOIN (all rows from left table), RIGHT OUTER JOIN (all rows from right table), and FULL OUTER JOIN (all rows from both tables).
Click to reveal answer
beginner
Give a real-life example where an outer join is useful.
Imagine a list of customers and their orders. Some customers may not have placed orders yet. A LEFT OUTER JOIN shows all customers, including those without orders, so we don't miss anyone.
Click to reveal answer
beginner
What happens to unmatched rows in an outer join?
Unmatched rows appear with NULL values in the columns of the table that has no matching row.
Click to reveal answer
Which join returns all rows from the left table and matching rows from the right table?
ALEFT OUTER JOIN
BINNER JOIN
CRIGHT OUTER JOIN
DCROSS JOIN
✗ Incorrect
LEFT OUTER JOIN returns all rows from the left table and matching rows from the right table, filling NULLs where no match exists.
What does an INNER JOIN do?
AReturns all rows from both tables
BReturns only matching rows from both tables
CReturns all rows from the left table
DReturns all rows from the right table
✗ Incorrect
INNER JOIN returns only rows where there is a match in both tables.
Why might you use a FULL OUTER JOIN?
ATo get only matching rows
BTo get only rows from the left table
CTo get only rows from the right table
DTo get all rows from both tables, including unmatched ones
✗ Incorrect
FULL OUTER JOIN returns all rows from both tables, showing NULLs where there is no match.
If you want to find customers without orders, which join helps?
AINNER JOIN
BRIGHT OUTER JOIN
CLEFT OUTER JOIN
DCROSS JOIN
✗ Incorrect
LEFT OUTER JOIN shows all customers including those without orders by keeping unmatched rows from the left table.
What value appears in columns of unmatched rows in an outer join?
ANULL
BEmpty string
CDefault value
D0
✗ Incorrect
Unmatched rows have NULL values in columns of the table without a matching row.
Explain why outer joins are important when working with related tables in a database.
Think about when you want to see all data even if some parts don't match.
You got /4 concepts.
Describe the difference between LEFT OUTER JOIN, RIGHT OUTER JOIN, and FULL OUTER JOIN.
Focus on which table's rows are fully included.
You got /4 concepts.
Practice
(1/5)
1. Why do we need LEFT OUTER JOIN in SQL?
easy
A. To include all rows from the left table even if there is no matching row in the right table
B. To only show rows that have matching values in both tables
C. To delete rows from the left table
D. To update rows in the right table
Solution
Step 1: Understand the purpose of LEFT OUTER JOIN
LEFT OUTER JOIN returns all rows from the left table and matched rows from the right table. If no match, NULLs appear for right table columns.
Step 2: Compare with INNER JOIN behavior
INNER JOIN returns only rows with matching keys in both tables, excluding unmatched rows.
Final Answer:
To include all rows from the left table even if there is no matching row in the right table -> Option A
Quick Check:
LEFT OUTER JOIN shows all left rows [OK]
Hint: LEFT OUTER JOIN keeps all left rows, unmatched get NULLs [OK]
Common Mistakes:
Confusing LEFT OUTER JOIN with INNER JOIN
Thinking it deletes or updates rows
Assuming it only shows matched rows
2. Which of the following is the correct syntax for a LEFT OUTER JOIN?
easy
A. SELECT * FROM table1 JOIN LEFT OUTER table2 ON table1.id = table2.id;
B. SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id;
C. SELECT * FROM table1 OUTER LEFT JOIN table2 ON table1.id = table2.id;
D. SELECT * FROM table1 LEFT OUTER JOIN table2 WHERE table1.id = table2.id;
Solution
Step 1: Recall correct LEFT OUTER JOIN syntax
The correct syntax is: SELECT ... FROM table1 LEFT JOIN table2 ON condition; LEFT JOIN is shorthand for LEFT OUTER JOIN.
Step 2: Identify syntax errors in other options
SELECT * FROM table1 JOIN LEFT OUTER table2 ON table1.id = table2.id; has JOIN LEFT OUTER which is invalid order. SELECT * FROM table1 OUTER LEFT JOIN table2 ON table1.id = table2.id; uses OUTER LEFT JOIN which is incorrect. SELECT * FROM table1 LEFT OUTER JOIN table2 WHERE table1.id = table2.id; uses WHERE instead of ON for join condition.
Final Answer:
SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id; -> Option B
Quick Check:
LEFT JOIN ... ON ... is correct syntax [OK]
Hint: Use LEFT JOIN ... ON ... for correct outer join syntax [OK]
Common Mistakes:
Swapping JOIN and LEFT keywords
Using WHERE instead of ON for join condition
Writing OUTER LEFT JOIN instead of LEFT OUTER JOIN
3. Given tables Employees and Departments where some employees have no department, what will this query return?
SELECT e.name, d.name FROM Employees e LEFT JOIN Departments d ON e.dept_id = d.id;
medium
A. All departments with employee names; NULL for departments without employees
B. Only employees who have a matching department
C. All employees with their department names; NULL for employees without a department
D. Only departments with employees
Solution
Step 1: Analyze LEFT JOIN behavior on Employees and Departments
LEFT JOIN keeps all rows from Employees (left table). For employees without matching department, department columns show NULL.
Step 2: Understand output columns
Query selects employee name and department name. Employees without department show NULL in department name.
Final Answer:
All employees with their department names; NULL for employees without a department -> Option C
Quick Check:
LEFT JOIN keeps all left rows, unmatched right columns NULL [OK]
Hint: LEFT JOIN shows all left rows, unmatched right side NULL [OK]
Common Mistakes:
Thinking only matched rows appear
Confusing left and right tables
Expecting departments without employees to appear
4. What is wrong with this query if we want to list all customers and their orders, including customers with no orders?
SELECT c.name, o.order_id FROM Customers c INNER JOIN Orders o ON c.id = o.customer_id;
medium
A. INNER JOIN excludes customers without orders; should use LEFT OUTER JOIN
B. The ON clause is missing
C. The SELECT statement is missing table aliases
D. Orders table should be first in the FROM clause
Solution
Step 1: Understand INNER JOIN behavior
INNER JOIN returns only rows with matching keys in both tables, so customers without orders are excluded.
Step 2: Identify correct join for including all customers
LEFT OUTER JOIN keeps all customers even if no matching orders exist, showing NULL for order columns.
Final Answer:
INNER JOIN excludes customers without orders; should use LEFT OUTER JOIN -> Option A
Quick Check:
Use LEFT OUTER JOIN to include all left table rows [OK]
Hint: Use LEFT OUTER JOIN to include unmatched left table rows [OK]
Common Mistakes:
Using INNER JOIN when outer join is needed
Forgetting ON clause (though present here)
Thinking table order in FROM matters for join type
5. You have two tables: Students and Enrollments. Some students are not enrolled in any course. Which query correctly lists all students and their courses, showing NULL for students without enrollments?
hard
A. SELECT s.name, e.course FROM Students s INNER JOIN Enrollments e ON s.id = e.student_id;
B. SELECT s.name, e.course FROM Students s RIGHT OUTER JOIN Enrollments e ON s.id = e.student_id;
C. SELECT s.name, e.course FROM Enrollments e LEFT OUTER JOIN Students s ON s.id = e.student_id;
D. SELECT s.name, e.course FROM Students s LEFT OUTER JOIN Enrollments e ON s.id = e.student_id;
Solution
Step 1: Identify which table has all students
Students table contains all students, including those without enrollments.
Step 2: Choose join to keep all students
LEFT OUTER JOIN with Students as left table keeps all students, adding course info or NULL if no enrollment.
Step 3: Evaluate other options
INNER JOIN excludes students without enrollments. RIGHT OUTER JOIN with Enrollments left excludes students without enrollments. LEFT OUTER JOIN with Enrollments left table excludes students without enrollments.
Final Answer:
SELECT s.name, e.course FROM Students s LEFT OUTER JOIN Enrollments e ON s.id = e.student_id; -> Option D
Quick Check:
LEFT OUTER JOIN keeps all left table rows [OK]
Hint: LEFT OUTER JOIN with Students on left keeps all students [OK]
Common Mistakes:
Using INNER JOIN excludes students without courses