Sobes.tech
Junior — Middle

How do connection types differ in SQL and what are their features?

sobes.tech AI

Answer from AI

In SQL, there are different types of joins that allow you to combine data from multiple tables:

  • INNER JOIN — returns only the rows where there are matches in both tables.
  • LEFT JOIN (or LEFT OUTER JOIN) — returns all rows from the left table and the matching rows from the right table; if there is no match, the result is NULL on the right side.
  • RIGHT JOIN — similar to LEFT JOIN, but returns all rows from the right table.
  • FULL JOIN (FULL OUTER JOIN) — returns all rows from both tables, filling in NULLs 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;

This query will return the names of employees and their departments only for those employees who have an assigned department.