What is a SQL JOIN?
Short answer
A JOIN combines rows from two or more tables using a matching column, such as a shared id. The join type decides which rows are kept: INNER keeps only matches, LEFT keeps all rows from the left table, and so on.
Why joins exist
Relational databases split data across tables to avoid duplication — users in one table, orders in another. A JOIN stitches them back together on a shared key (like user_id) so a single query can return combined rows.
The join types
INNER JOIN— only rows with a match in both tablesLEFT JOIN— all rows from the left table, plus matches from the right (NULLs where none)RIGHT JOIN— all rows from the right table, plus matches from the leftFULL JOIN— all rows from both tables, matched where possibleCROSS JOIN— every row of the first table paired with every row of the second
SELECT users.name, orders.total
FROM users
LEFT JOIN orders ON orders.user_id = users.id;The ON condition
The ON clause defines how rows match. Get it wrong and you either lose rows or multiply them (a partial or missing condition can cause an accidental CROSS JOIN). Test joins on real data before trusting them. See how to write a SQL query.