Sobes.tech
Junior — Middle

What methods can be used to perform table joins in a database?

sobes.tech AI

Answer from AI

In databases, different types of JOINs are used to connect tables, allowing you to combine rows from two or more tables based on related fields:

  • INNER JOIN — returns only the records that have matches in both tables.
  • LEFT JOIN (LEFT OUTER JOIN) — returns all records from the left table and the matching records from the right; if there are no matches, NULLs are shown for right table fields.
  • 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; where there are no matches, NULLs are shown in the respective fields.
  • CROSS JOIN — Cartesian product of two tables, each row of the first table is combined with every row of the second.

Example of INNER JOIN:

SELECT orders.id, customers.name
FROM orders
INNER JOIN customers ON orders.customer_id = customers.id;
What methods can be used to perform table joins in a… - sobes.tech