Sobes.tech
Junior — Middle

Can you tell about the different types of table joins in SQL?

sobes.tech AI

Answer from AI

In SQL, there are several main types of table joins (JOIN) that allow combining data from different tables:

  • 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 ones from the right; if there are no matches, NULLs will appear on the right side.
  • RIGHT JOIN (RIGHT OUTER JOIN) — the opposite, returns all 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.

Example of INNER JOIN:

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