🔹 FULL JOIN in SQL

Definition:
The FULL JOIN clause returns all records when there is a match in either left or right table. Records without a match in either table will have NULLs for the missing side.
Syntax:
SELECT table1.column, table2.column
FROM table1
FULL JOIN table2
ON table1.common_column = table2.common_column;
Example:
SELECT Employees.name, Departments.department_name
FROM Employees
FULL JOIN Departments
ON Employees.department_id = Departments.department_id;
Sample Employees Table:
idnamedepartment_id
1Alice101
2Bob102
3Charlie103
Sample Departments Table:
department_iddepartment_name
101HR
102Engineering
104Finance
Output:
namedepartment_name
AliceHR
BobEngineering
CharlieNULL
NULLFinance
Explanation:
The query returns all rows from both Employees and Departments: - Alice (101) → HR - Bob (102) → Engineering - Charlie (103) → No match in Departments → **NULL** - Finance (104) → No matching employee → **NULL**

FULL JOIN includes all rows from both tables, with NULLs where no match exists.
Usage Tips:
  • Use FULL JOIN when you want all rows from both tables, matched or unmatched.
  • Helps identify gaps or mismatches between two related datasets.
Common Mistake:
Assuming FULL JOIN behaves like INNER JOIN. Unlike INNER JOIN, FULL JOIN includes unmatched rows from both sides.
📘 Note: FULL JOIN is also called FULL OUTER JOIN; both mean the same.
➡️ Next: SELF JOIN