Sobes.tech
Junior — Middle

Can you name the main types of table joins in SQL that you use to combine data?

sobes.tech AI

Answer from AI

The main types of SQL joins for combining data from multiple tables:

  • INNER JOIN — returns rows with matching values in both tables.
  • LEFT JOIN (LEFT OUTER JOIN) — returns all rows from the left table and matching rows from the right; if no match, NULLs are used.
  • RIGHT JOIN (RIGHT OUTER JOIN) — returns all rows from the right table and matching rows from the left.
  • FULL JOIN (FULL OUTER JOIN) — returns all rows from both tables, filling with NULLs where there are no matches.
  • CROSS JOIN — Cartesian product of two tables, each row of the first table is combined with each row of the second.

Example of INNER JOIN:

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

This query returns user names and their orders only if the user has orders.