Middle
What types of JOIN are there?
sobes.tech AI
Answer from AI
In SQL, there are several main types of JOINs that allow you to combine rows from two or more tables based on a specific condition:
- INNER JOIN — returns only the rows where there are matches in both tables.
- LEFT JOIN (LEFT OUTER JOIN) — returns all rows from the left table and the matching rows from the right; if there are no matches, NULLs are used for the right table.
- RIGHT JOIN (RIGHT OUTER JOIN) — similar to LEFT JOIN, but returns all rows from the right table and the matching rows from the left.
- FULL JOIN (FULL OUTER JOIN) — returns all rows from both tables; where there are no matches, NULLs are used in the respective fields.
- 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;