Junior — Middle
Can you name the main types of table joins in SQL and their features?
sobes.tech AI
Answer from AI
Main types of JOINs in SQL:
- INNER JOIN — returns only the records that match the condition in both tables.
- LEFT JOIN (LEFT OUTER JOIN) — returns all records from the left table and the matching records from the right; if there are no matches, NULLs will appear on the right side.
- RIGHT JOIN (RIGHT OUTER JOIN) — the opposite, all records from the right table and the matching ones from the left.
- FULL JOIN (FULL OUTER JOIN) — returns all records from both tables, with NULLs in places where there are no matches.
- CROSS JOIN — Cartesian product of two tables, returning all possible combinations of rows.
Example of INNER JOIN:
SELECT users.name, orders.id
FROM users
INNER JOIN orders ON users.id = orders.user_id;