Sobes.tech
Junior — Middle

Kas saaksite loetleda SQL-i erinevaid tabelite ühendamise tüüpe ja kirjeldada nende omadusi?

sobes.tech AI

Vastus AI-lt

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

  • 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, the right side values will be NULL.
  • 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, filling with NULL where there are no matches.
  • CROSS JOIN — Cartesian product, each row from the first table is combined with each row from the second.

Example of INNER JOIN:

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

This query will return users who have orders.