Learn SQL
SQL JOINs Explained: INNER, LEFT, FULL OUTER, SELF, and CROSS JOIN
JOINs bring related tables back together: matched rows, missing matches, hierarchies, and all-combination grids all use different JOIN patterns.
On This Page
INNER JOIN keeps matching rows
INNER JOIN returns rows where the join condition matches on both sides. If an employee has no matching department, that employee is excluded.
SELECT e.name AS employee_name, d.name AS department_name
FROM employees AS e
INNER JOIN departments AS d
ON e.department_id = d.id;LEFT and FULL OUTER JOIN keep unmatched rows
LEFT JOIN keeps every row from the left table and uses NULL when the right side has no match. FULL OUTER JOIN keeps unmatched rows from both sides.
SELECT d.name AS department_name, e.name AS employee_name
FROM departments AS d
LEFT JOIN employees AS e
ON d.id = e.department_id;Finding missing matches
LEFT JOIN plus WHERE right_table.id IS NULL is a classic pattern for finding gaps in related data.
SELF JOIN and CROSS JOIN solve special shapes
A SELF JOIN connects rows in a table to other rows in the same table, such as employees to managers. A CROSS JOIN creates every possible combination between two tables, such as departments and meeting days.
SELECT e.name AS employee_name, m.name AS manager_name
FROM employees AS e
LEFT JOIN employees AS m
ON e.manager_id = m.id;Practice the JOIN Types chapter
- Start with why JOINs exist and how keys connect tables.
- Use INNER JOIN for matching rows and LEFT JOIN for preserving one side.
- Find missing matches with LEFT JOIN and IS NULL.
- Finish with FULL OUTER, SELF, and CROSS JOIN patterns.
Continue in the editor
Open SQL for Files to add your own CSV, JSON, or Parquet files and try these examples locally in your browser.
Open editorRelated guides
Database Normalization Explained: Why Clean Tables Need Keys, JOINs, and Normal Forms
Normalization keeps each fact in the right place, reducing duplicated data and making updates, inserts, and deletes safer.
SQL NULL Explained: How Missing Values Work and Why They Matter
NULL is SQL's way of saying a value is missing or unknown — and it behaves differently from almost every other value beginners expect.
Practical SQL Examples for CSV, JSON, and Parquet Files
A compact collection of SQL patterns you can adapt for local file analysis in SQL for Files.