Sobes.tech
Junior — Middle

Kas saame loetleda SQL-i tabelite peamised ühendustüübid ja selgitada nende kasutamist?

sobes.tech AI

Vastus AI-lt

Main types of joins in SQL:

  • INNER JOIN — returns only the records that match the join condition in both tables.
  • LEFT JOIN (LEFT OUTER JOIN) — returns all records from the left table and the matching records from the right; if there is no match, the right side columns will be NULL.
  • RIGHT JOIN (RIGHT OUTER JOIN) — the opposite, returns all records from the right table and the matching ones from the left.
  • FULL JOIN (FULL OUTER JOIN) — returns all records from both tables, matching and non-matching, with NULL where there is no match.
  • CROSS JOIN — Cartesian product of two tables, returns all possible row combinations.

Example of using INNER JOIN:

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

Here, employee names and their department names are selected, only for employees with a corresponding department.