Middle+
What is a join and what types are there?
sobes.tech AI
Answer from AI
Join is an operation in relational databases that allows combining rows from two or more tables based on a related condition.
Main types of join:
- INNER JOIN — returns only the records that have matches in both tables.
- LEFT JOIN (LEFT OUTER JOIN) — returns all records from the left table and matching records from the right; if there are no matches, NULLs will appear on the right.
- RIGHT JOIN (RIGHT OUTER JOIN) — the opposite, returns all from the right table and matching from the left.
- FULL JOIN (FULL OUTER JOIN) — returns all records from both tables, filling NULL where there are no matches.
- CROSS JOIN — Cartesian product, all possible combinations of rows from both tables.
Example of INNER JOIN:
SELECT users.name, orders.id
FROM users
INNER JOIN orders ON users.id = orders.user_id;