Junior
What join methods in SQL do you know?
sobes.tech AI
Answer from AI
In SQL, there are several main types of joins that allow you to combine data from two or more tables:
- 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 side.
- RIGHT JOIN (RIGHT OUTER JOIN) — similar to LEFT JOIN, but returns all records from the right table.
- FULL JOIN (FULL OUTER JOIN) — returns all records from both tables, with NULLs in the fields where there are no matches.
- CROSS JOIN — Cartesian product of two tables, returning all possible combinations of rows.
Example of INNER JOIN:
SELECT employees.name, departments.name
FROM employees
INNER JOIN departments ON employees.department_id = departments.id;