Sobes.tech
Junior — Middle

Kas saaksite selgitada, mida tähendab tabelite ühendamise operatsioon SQL-is?

sobes.tech AI

Vastus AI-lt

The table join operation in SQL (JOIN) allows linking rows from two or more tables based on a logical condition, usually matching values in specific columns (e.g., by keys).

Main types of joins:

  • INNER JOIN — returns only the rows that have 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 is no match, the right columns will be NULL.
  • RIGHT JOIN (RIGHT OUTER JOIN) — conversely, 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 is no match.

Example:

SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;

This query joins the Orders and Customers tables on CustomerID and returns the orders with customer names.