Part 5: Understanding FULL JOIN

Part 5: Understanding FULL JOIN | SQL Challenges & Capstone
SQL Joins & Advanced Group Filtering Practice Β· Part 5 Β· Lecture Notes

Understanding FULL JOIN

How to combine all records from both tables β€” simulated in MySQL using LEFT JOIN UNION RIGHT JOIN β€” for complete relationship visibility and data quality audits.

Part 5 of 5100% Complete
FULL JOIN
LEFT JOIN UNION RIGHT JOIN
All Records Both Sides
Complete Visibility
8 Practice Questions

Learning Objectives

  • Understand that FULL JOIN returns all records from both tables with NULLs where no match exists
  • Simulate FULL JOIN in MySQL using LEFT JOIN UNION RIGHT JOIN
  • Understand how UNION removes duplicate rows from the combined result
  • Identify the three row types in FULL JOIN output: matched rows, left-only rows, and right-only rows
Click any section header to open or close it

FULL JOIN returns all records from both tables β€” rows that have matches appear with complete data from both sides, and rows without a match appear with NULL in the columns from the other table. FULL JOIN is the most inclusive join type: no row from either table is excluded.

In industry, analysts use FULL JOIN to analyze complete business relationships, identify missing matches on both sides simultaneously, perform data completeness checks across two tables, combine all operational records for full visibility, and review both linked and unlinked activity in one output.

MySQL Does Not Support FULL JOIN Directly

MySQL does not have a native FULL JOIN keyword. Analysts simulate FULL JOIN using a LEFT JOIN combined with a RIGHT JOIN using UNION, which merges the two result sets and removes duplicates. This is the standard MySQL pattern for full outer join behaviour.

FULL JOIN Simulation in MySQL β€” Campaign Events
SELECT c.campaign_id, c.campaign_name, ce.event_type FROM campaigns c LEFT JOIN campaign_events ce ON c.campaign_id = ce.campaign_id UNION SELECT c.campaign_id, c.campaign_name, ce.event_type FROM campaigns c RIGHT JOIN campaign_events ce ON c.campaign_id = ce.campaign_id;

The UNION of a LEFT JOIN and a RIGHT JOIN produces FULL JOIN behaviour. The LEFT JOIN captures all left-table rows (including non-matching ones). The RIGHT JOIN captures all right-table rows (including non-matching ones). UNION merges both result sets and automatically removes duplicate rows β€” the matched rows that appear in both.

How UNION Works Here

UNION combines two SELECT results into one, removing duplicate rows. In the FULL JOIN simulation, matched rows appear in both the LEFT JOIN and RIGHT JOIN results. UNION removes the duplicates, leaving: all matched rows + all unmatched left rows + all unmatched right rows = full outer join.

All Users and All Transactions (FULL JOIN)
SELECT users.first_name, transactions.amount FROM users LEFT JOIN transactions ON users.user_id = transactions.user_id UNION SELECT users.first_name, transactions.amount FROM users RIGHT JOIN transactions ON users.user_id = transactions.user_id;

FULL JOIN provides the most complete picture of any two-table relationship. Every user appears β€” whether they have an order or not. Every order appears β€” whether its user_id matches a user or not. The result shows the full landscape: matched pairs, users without orders, and orders without users all in one output.

When to Use FULL JOIN

FULL JOIN is most valuable for data quality audits, completeness reports, and full reconciliation across two tables. For standard analytics, LEFT JOIN or INNER JOIN usually suffices. Reserve FULL JOIN for situations where missing data on both sides needs to be visible simultaneously.

All Users and All Orders (FULL JOIN)
SELECT users.first_name, orders.order_status FROM users LEFT JOIN orders ON users.user_id = orders.user_id UNION SELECT users.first_name, orders.order_status FROM users RIGHT JOIN orders ON users.user_id = orders.user_id;

FULL JOIN exposes two types of gaps simultaneously: left-side records with no match (NULL in right-table columns) and right-side records with no match (NULL in left-table columns). This dual gap visibility makes FULL JOIN the standard tool for reconciliation β€” verifying that all records on both sides are properly linked.

NULL Patterns in FULL JOIN Output

Three row types appear in FULL JOIN output: rows where both sides match (no NULLs from the join), rows where only the left side exists (NULLs in right columns), and rows where only the right side exists (NULLs in left columns). These three patterns describe the complete state of the relationship.

All Users and All Subscriptions (FULL JOIN)
SELECT users.first_name, subscriptions.status FROM users LEFT JOIN subscriptions ON users.user_id = subscriptions.user_id UNION SELECT users.first_name, subscriptions.status FROM users RIGHT JOIN subscriptions ON users.user_id = subscriptions.user_id;

Work through each question below. Run your query first, then use Check Answer. A wrong answer reveals the correct SQL with a Copy button; a correct result earns a congratulations message.

Practice 1 Retrieve all users and all transaction amounts rounded to 2 decimal places using FULL JOIN logic
AI Prompt
Write a MySQL query to retrieve all users and all transaction amounts rounded to 2 decimal places using FULL JOIN logic.
SQL Answer
SELECT users.first_name, ROUND(transactions.amount, 2) AS amount FROM users LEFT JOIN transactions ON users.user_id = transactions.user_id UNION SELECT users.first_name, ROUND(transactions.amount, 2) AS amount FROM users RIGHT JOIN transactions ON users.user_id = transactions.user_id;
Practice 2 Retrieve all users and all order statuses using FULL JOIN logic
AI Prompt
Write a MySQL query to retrieve all users and all order statuses using FULL JOIN logic.
SQL Answer
SELECT users.first_name, orders.order_status FROM users LEFT JOIN orders ON users.user_id = orders.user_id UNION SELECT users.first_name, orders.order_status FROM users RIGHT JOIN orders ON users.user_id = orders.user_id;
Practice 3 Retrieve all products and all order item quantities using FULL JOIN logic
AI Prompt
Write a MySQL query to retrieve all products and all order item quantities using FULL JOIN logic.
SQL Answer
SELECT products.product_name, order_items.quantity FROM products LEFT JOIN order_items ON products.product_id = order_items.product_id UNION SELECT products.product_name, order_items.quantity FROM products RIGHT JOIN order_items ON products.product_id = order_items.product_id;
Practice 4 Retrieve all users and all subscription monthly_fee values rounded to 2 decimal places using FULL JOIN logic
AI Prompt
Write a MySQL query to retrieve all users and all subscription monthly_fee values rounded to 2 decimal places using FULL JOIN logic.
SQL Answer
SELECT users.first_name, ROUND(subscriptions.monthly_fee, 2) AS monthly_fee FROM users LEFT JOIN subscriptions ON users.user_id = subscriptions.user_id UNION SELECT users.first_name, ROUND(subscriptions.monthly_fee, 2) AS monthly_fee FROM users RIGHT JOIN subscriptions ON users.user_id = subscriptions.user_id;
Practice 5 Retrieve all users and all support ticket statuses using FULL JOIN logic
AI Prompt
Write a MySQL query to retrieve all users and all support ticket statuses using FULL JOIN logic.
SQL Answer
SELECT users.first_name, support_tickets.ticket_status FROM users LEFT JOIN support_tickets ON users.user_id = support_tickets.user_id UNION SELECT users.first_name, support_tickets.ticket_status FROM users RIGHT JOIN support_tickets ON users.user_id = support_tickets.user_id;
Practice 6 Retrieve all users and all campaign event types using FULL JOIN logic
AI Prompt
Write a MySQL query to retrieve all users and all campaign event types using FULL JOIN logic.
SQL Answer
SELECT users.first_name, campaign_events.event_type FROM users LEFT JOIN campaign_events ON users.user_id = campaign_events.user_id UNION SELECT users.first_name, campaign_events.event_type FROM users RIGHT JOIN campaign_events ON users.user_id = campaign_events.user_id;
Practice 7 Retrieve all orders and all product names using FULL JOIN logic
AI Prompt
Write a MySQL query to retrieve all orders and all product names using FULL JOIN logic.
SQL Answer
SELECT orders.order_id, products.product_name FROM orders LEFT JOIN order_items ON orders.order_id = order_items.order_id LEFT JOIN products ON order_items.product_id = products.product_id UNION SELECT orders.order_id, products.product_name FROM orders RIGHT JOIN order_items ON orders.order_id = order_items.order_id RIGHT JOIN products ON order_items.product_id = products.product_id;
Practice 8 Retrieve all users and all session device types using FULL JOIN logic
AI Prompt
Write a MySQL query to retrieve all users and all session device types using FULL JOIN logic.
SQL Answer
SELECT users.first_name, sessions.device_type FROM users LEFT JOIN sessions ON users.user_id = sessions.user_id UNION SELECT users.first_name, sessions.device_type FROM users RIGHT JOIN sessions ON users.user_id = sessions.user_id;

Knowledge Check

Five questions β€” select the best answer for each.

1. What does FULL JOIN return?
AOnly records that match in both tables
BAll records from the left table only
CAll records from both tables β€” matched and unmatched β€” with NULLs where no match exists
DAll records from the right table only
2. Why does MySQL require LEFT JOIN UNION RIGHT JOIN to simulate FULL JOIN?
AMySQL has a bug that prevents FULL JOIN from working
BMySQL does not support the FULL JOIN keyword and requires this workaround
CUNION is always required before any JOIN in MySQL
DLEFT JOIN and RIGHT JOIN produce identical results in MySQL
3. What does UNION do in the FULL JOIN simulation?
AIt filters out NULL rows from both join results
BIt combines the LEFT JOIN and RIGHT JOIN results and removes duplicate rows
CIt sorts the combined result alphabetically
DIt requires both SELECT statements to return the same number of rows
4. In FULL JOIN output, what does NULL in both table columns on a single row indicate?
AA row that matched in both tables but had NULL data values
BThis cannot happen in FULL JOIN β€” there are no fully NULL rows
CA data entry error
DIt depends on the JOIN condition
5. When is FULL JOIN most analytically valuable?
AWhen you want only matching records from both tables
BWhen you want to preserve all left-table records
CWhen you need complete visibility of both sides including all missing matches from either side
DWhen you want to sort results alphabetically

Part 5 Summary

The key ideas from this lecture β€” keep these in mind as you move forward.

FULL JOIN helps analysts combine all matching and non-matching records across business datasets to achieve complete relationship visibility. MySQL simulates FULL JOIN using LEFT JOIN UNION RIGHT JOIN. Three row types appear: matched, left-only, and right-only.

FULL JOINUNIONLEFT JOINRIGHT JOINAll RecordsNULL PatternsComplete VisibilityReconciliationData Quality