Sobes.tech
Principal

What is a JOIN in databases, and what types are there?

sobes.tech AI

Answer from AI

JOIN is an operation in relational databases that allows combining rows from two or more tables based on a related column.

Main types of JOIN:

  • INNER JOIN — returns only the records with 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.
  • RIGHT JOIN (RIGHT OUTER JOIN) — the opposite, returns all from the right table and matching from the left.
  • FULL JOIN (FULL OUTER JOIN) — returns all records from both tables, filling NULLs where there are no matches.

Example in SQL:

SELECT users.name, orders.id
FROM users
INNER JOIN orders ON users.id = orders.user_id;

This query will return the names of users and their orders, only for users who have orders.