Relational databases store data across multiple tables. Joins let you combine rows from those tables based on a related column.
Why Joins Matter
Instead of duplicating data everywhere, you normalize it into separate tables (e.g. users and orders) and join them together when you need combined results.
INNER JOIN
Returns only rows that have matching values in both tables.
sql
SELECT users.name, orders.total
FROM users
INNER JOIN orders ON users.id = orders.user_id;
LEFT JOIN
Returns all rows from the left table, plus matches from the right table — unmatched rows show NULL.
sql
SELECT users.name, orders.total
FROM users
LEFT JOIN orders ON users.id = orders.user_id;
RIGHT JOIN
The mirror of LEFT JOIN — returns all rows from the right table, with matches from the left.
sql
SELECT users.name, orders.total
FROM users
RIGHT JOIN orders ON users.id = orders.user_id;
FULL OUTER JOIN
Returns all rows from both tables, matching where possible and filling NULL elsewhere.
sql
SELECT users.name, orders.total
FROM users
FULL OUTER JOIN orders ON users.id = orders.user_id;
SQLDatabasesBeginner