Bird
Raised Fist0
SQLquery~20 mins

FULL OUTER JOIN behavior in SQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

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
Challenge - 5 Problems
🎖️
FULL OUTER JOIN Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of FULL OUTER JOIN with partial matches

Consider two 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.id, Employees.name, Departments.dept_name
FROM Employees
FULL OUTER JOIN Departments ON Employees.id = Departments.id
ORDER BY Employees.id NULLS LAST, Departments.id NULLS LAST;
SQL
SELECT Employees.id, Employees.name, Departments.dept_name
FROM Employees
FULL OUTER JOIN Departments ON Employees.id = Departments.id
ORDER BY Employees.id NULLS LAST, Departments.id NULLS LAST;
A
1 | Alice | NULL
2 | Bob | Sales
3 | Carol | HR
NULL | NULL | IT
B
1 | Alice | NULL
2 | Bob | Sales
3 | Carol | HR
C
2 | Bob | Sales
3 | Carol | HR
4 | NULL | IT
D
1 | Alice | NULL
2 | Bob | Sales
3 | Carol | HR
4 | NULL | IT
Attempts:
2 left
💡 Hint

FULL OUTER JOIN returns all rows from both tables, matching where possible, and NULL where no match exists.

🧠 Conceptual
intermediate
1:30remaining
Understanding NULLs in FULL OUTER JOIN results

When using FULL OUTER JOIN between two tables, which statement about NULL values in the result is true?

ANULLs appear only in columns from the left table when there is no match.
BNULLs appear only in columns from the right table when there is no match.
CNULLs never appear in FULL OUTER JOIN results.
DNULLs appear in columns from either table when there is no matching row in the other table.
Attempts:
2 left
💡 Hint

Think about what happens when a row exists in one table but not the other.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in FULL OUTER JOIN query

Which of the following SQL queries will cause a syntax error?

SELECT A.id, B.name
FROM TableA A
FULL OUTER JOIN TableB B ON A.id = B.id
ASELECT A.id, B.name FROM TableA A FULL OUTER JOIN TableB B ON A.id = B.id;
BSELECT A.id, B.name FROM TableA A FULL JOIN TableB B ON A.id = B.id;
CSELECT A.id, B.name FROM TableA A OUTER FULL JOIN TableB B ON A.id = B.id;
DSELECT A.id, B.name FROM TableA A LEFT JOIN TableB B ON A.id = B.id;
Attempts:
2 left
💡 Hint

Check the order of keywords in the JOIN clause.

optimization
advanced
2:00remaining
Optimizing FULL OUTER JOIN queries for large tables

You have two large tables with millions of rows each. You want to perform a FULL OUTER JOIN on a key column. Which approach can improve query performance?

ACreate indexes on the join key columns in both tables before running the FULL OUTER JOIN.
BUse CROSS JOIN instead of FULL OUTER JOIN to get all combinations and filter later.
CRemove indexes on join keys to speed up the join operation.
DUse a subquery to select all rows from one table and then LEFT JOIN the other table.
Attempts:
2 left
💡 Hint

Indexes help the database find matching rows faster.

🔧 Debug
expert
2:30remaining
Diagnose unexpected NULLs in FULL OUTER JOIN result

You run this query:

SELECT A.id, A.value, B.value
FROM TableA A
FULL OUTER JOIN TableB B ON A.id = B.id
WHERE A.value > 10;

You notice that rows with NULL in A.value do not appear in the result. Why?

AThe WHERE clause filters after the FULL OUTER JOIN, so rows with NULL A.value pass the filter.
BThe condition A.value > 10 excludes rows where A.value is NULL, so those rows should not appear.
CThe WHERE clause filters before the FULL OUTER JOIN, so NULLs in A.value are ignored.
DThe FULL OUTER JOIN duplicates rows with NULL values in A.value.
Attempts:
2 left
💡 Hint

Think about when the WHERE clause is applied in relation to the JOIN.

Practice

(1/5)
1. What does a FULL OUTER JOIN do in SQL?
easy
A. Returns all rows from the left table and matching rows from the right table.
B. Returns only rows that have matching values in both tables.
C. Returns all rows from both tables, matching where possible and NULLs where no match exists.
D. Returns all rows from the right table and matching rows from the left table.

Solution

  1. Step 1: Understand join types

    INNER JOIN returns only matching rows; LEFT JOIN returns all from left plus matches; RIGHT JOIN returns all from right plus matches.
  2. Step 2: Define FULL OUTER JOIN behavior

    FULL OUTER JOIN returns all rows from both tables, matching where possible, and fills NULLs where no match exists.
  3. Final Answer:

    Returns all rows from both tables, matching where possible and NULLs where no match exists. -> Option C
  4. Quick Check:

    FULL OUTER JOIN = all rows both tables [OK]
Hint: Full outer join keeps all rows from both tables [OK]
Common Mistakes:
  • Confusing FULL OUTER JOIN with INNER JOIN
  • Thinking FULL OUTER JOIN returns only matches
  • Mixing up LEFT and RIGHT JOIN behavior
2. Which of the following is the correct syntax for a FULL OUTER JOIN between tables Employees and Departments on DeptID?
easy
A. SELECT * FROM Employees FULL OUTER JOIN Departments ON Employees.DeptID = Departments.DeptID;
B. SELECT * FROM Employees INNER JOIN Departments ON Employees.DeptID = Departments.DeptID;
C. SELECT * FROM Employees LEFT JOIN Departments ON Employees.DeptID = Departments.DeptID;
D. SELECT * FROM Employees RIGHT JOIN Departments ON Employees.DeptID = Departments.DeptID;

Solution

  1. Step 1: Identify FULL OUTER JOIN syntax

    The correct syntax uses the keywords FULL OUTER JOIN between the two tables with an ON condition.
  2. Step 2: Compare options

    SELECT * FROM Employees FULL OUTER JOIN Departments ON Employees.DeptID = Departments.DeptID; uses FULL OUTER JOIN correctly; others use INNER, LEFT, or RIGHT JOIN which are different join types.
  3. Final Answer:

    SELECT * FROM Employees FULL OUTER JOIN Departments ON Employees.DeptID = Departments.DeptID; -> Option A
  4. Quick Check:

    FULL OUTER JOIN syntax = SELECT * FROM Employees FULL OUTER JOIN Departments ON Employees.DeptID = Departments.DeptID; [OK]
Hint: FULL OUTER JOIN syntax includes FULL OUTER JOIN keywords [OK]
Common Mistakes:
  • Using INNER JOIN instead of FULL OUTER JOIN
  • Omitting FULL keyword and writing only OUTER JOIN
  • Confusing LEFT or RIGHT JOIN with FULL OUTER JOIN
3. Given these tables:

Table A:
ID | Name
1 | Alice
2 | Bob
4 | Dana

Table B:
ID | City
2 | Boston
3 | Chicago
4 | Denver

What is the result of this query?
SELECT A.ID, A.Name, B.City FROM A FULL OUTER JOIN B ON A.ID = B.ID ORDER BY A.ID;
medium
A. [ (1, 'Alice', NULL), (2, 'Bob', NULL), (3, NULL, 'Chicago'), (4, 'Dana', NULL) ]
B. [ (2, 'Bob', 'Boston'), (4, 'Dana', 'Denver') ]
C. [ (1, 'Alice', 'Boston'), (2, 'Bob', 'Chicago'), (3, NULL, 'Denver'), (4, 'Dana', NULL) ]
D. [ (1, 'Alice', NULL), (2, 'Bob', 'Boston'), (4, 'Dana', 'Denver'), (NULL, NULL, 'Chicago') ]

Solution

  1. Step 1: Match rows by ID using FULL OUTER JOIN

    IDs 2 and 4 appear in both tables, so their rows combine. ID 1 is only in A, ID 3 only in B.
  2. Step 2: Fill NULLs for missing matches

    For ID 1 (A only), City is NULL; for ID 3 (B only), A.ID=NULL, A.Name=NULL, City='Chicago'. ORDER BY A.ID ASC places NULL last: rows for 1,2,4 then NULL row.
  3. Final Answer:

    [ (1, 'Alice', NULL), (2, 'Bob', 'Boston'), (4, 'Dana', 'Denver'), (NULL, NULL, 'Chicago') ] -> Option D
  4. Quick Check:

    FULL OUTER JOIN returns all rows with NULLs for missing matches [OK]
Hint: FULL OUTER JOIN shows all rows, NULLs where no match [OK]
Common Mistakes:
  • Ignoring unmatched rows from either table
  • Assuming INNER JOIN behavior returns only matches
  • Misordering results by A.ID when NULLs exist
4. Consider this query:
SELECT * FROM Customers FULL OUTER JOIN Orders ON Customers.CustomerID = Orders.CustomerID WHERE Orders.OrderID IS NULL;

What is the likely purpose of this query?
medium
A. To find orders without customers.
B. To find customers who have no orders.
C. To find all customers and orders regardless of match.
D. To find customers with at least one order.

Solution

  1. Step 1: Understand FULL OUTER JOIN with WHERE filter

    The join returns all customers and orders; filtering WHERE Orders.OrderID IS NULL keeps rows where no matching order exists.
  2. Step 2: Interpret the filter effect

    Rows with NULL in Orders.OrderID mean customers without orders are selected.
  3. Final Answer:

    To find customers who have no orders. -> Option B
  4. Quick Check:

    Filter NULL in Orders = customers without orders [OK]
Hint: Filter NULL in joined table to find unmatched rows [OK]
Common Mistakes:
  • Thinking it finds orders without customers
  • Assuming it returns all rows without filtering
  • Confusing NULL filter with matching rows
5. You have two tables:

Products:
ProductID | Name
1 | Pen
2 | Pencil
3 | Eraser

Sales:
ProductID | Quantity
2 | 100
3 | 50
4 | 10

You want a query to list all products and sales quantities, including products with no sales and sales for unknown products.

Which query correctly achieves this?
hard
A. SELECT Products.ProductID, Products.Name, Sales.Quantity FROM Products FULL OUTER JOIN Sales ON Products.ProductID = Sales.ProductID;
B. SELECT Products.ProductID, Products.Name, Sales.Quantity FROM Products LEFT JOIN Sales ON Products.ProductID = Sales.ProductID;
C. SELECT Products.ProductID, Products.Name, Sales.Quantity FROM Sales RIGHT JOIN Products ON Sales.ProductID = Products.ProductID;
D. SELECT Products.ProductID, Products.Name, Sales.Quantity FROM Products INNER JOIN Sales ON Products.ProductID = Sales.ProductID;

Solution

  1. Step 1: Identify requirement for all products and all sales

    We want all products even if no sales, and all sales even if product unknown.
  2. Step 2: Choose join type

    FULL OUTER JOIN returns all rows from both tables, matching where possible, filling NULLs otherwise.
  3. Step 3: Check options

    SELECT Products.ProductID, Products.Name, Sales.Quantity FROM Products FULL OUTER JOIN Sales ON Products.ProductID = Sales.ProductID; uses FULL OUTER JOIN correctly; others exclude unmatched rows from one side.
  4. Final Answer:

    SELECT Products.ProductID, Products.Name, Sales.Quantity FROM Products FULL OUTER JOIN Sales ON Products.ProductID = Sales.ProductID; -> Option A
  5. Quick Check:

    FULL OUTER JOIN = all products and sales [OK]
Hint: Use FULL OUTER JOIN to include all rows from both tables [OK]
Common Mistakes:
  • Using LEFT JOIN excludes sales without products
  • Using INNER JOIN excludes unmatched rows
  • Confusing RIGHT JOIN direction with LEFT JOIN