Sobes.tech
Junior — Middle

How can you determine the features and types of JOIN operations in SQL queries?

sobes.tech AI

Answer from AI

SQL JOIN operations are used to combine rows from two or more tables based on a related condition.

Main types of JOIN:

  • INNER JOIN — returns only the rows where there is a match in both tables.
  • LEFT JOIN (LEFT OUTER JOIN) — returns all rows from the left table and the matching rows from the right; if there is no match, NULLs are used for the right table.
  • RIGHT JOIN (RIGHT OUTER JOIN) — the opposite, 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 is no match, NULLs are used.
  • CROSS JOIN — Cartesian product of two tables, each row of the first table is combined with each row of the second.

Example of INNER JOIN:

SELECT employees.name, departments.name
FROM employees
INNER JOIN departments ON employees.department_id = departments.id;

This selects employee names and their department names only if the relationship exists.