๐ŸŒ FULL JOIN โ€“ Show All Rows from Both Tables, Matched or Not

(because sometimes you need everything from both sides)

๐Ÿ”ง Quick Syntax

SELECT columns
FROM table1
FULL JOIN table2
ON table1.column = table2.column;

This says:
“Give me all rows from both tables, and match anything where possible. If thereโ€™s no match, show NULL.”

๐Ÿ‘€ Imagine You Have These Two Tables

๐Ÿง‘ employees table:

emp_idname
1Olivia
2Mason
3Zoe

๐Ÿ› ๏ธ projects table:

project_idemp_idproject_name
2011Website
2022App
2034Database

Now, you want to know which employees are assigned to projects, but you also want to see any employees who aren’t assigned, and any projects without employees.

๐Ÿ”ง FULL JOIN Syntax

SELECT employees.name, projects.project_name
FROM employees
FULL JOIN projects
ON employees.emp_id = projects.emp_id;

SQL will give you everything from both tables.
If thereโ€™s no match, you get NULL.

โœ… Result

nameproject_name
OliviaWebsite
MasonApp
ZoeNULL
NULLDatabase

Notice:
Zoe is an employee, but doesnโ€™t have a project, so sheโ€™s shown with NULL for project_name.
– The Database project doesnโ€™t have a matching employee, so itโ€™s shown with NULL for name.

๐Ÿ” LEFT JOIN vs RIGHT JOIN vs FULL JOIN

TypeWhoโ€™s Shown
LEFT JOINAll rows from the left, matches from the right
RIGHT JOINAll rows from the right, matches from the left
FULL JOINAll rows from both tables, matches or not

๐Ÿงƒ Recap

  • FULL JOIN gives you all rows from both tables, with NULL for missing matches
  • Use FULL JOIN when you need everything from both tables โ€” whether or not thereโ€™s a match

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top