Junior — Middle
Can you explain what a table join operation in SQL means?
sobes.tech AI
Answer from AI
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., keys).
Main types of joins:
- INNER JOIN — returns only those rows that have matches in both tables.
- LEFT JOIN (LEFT OUTER JOIN) — returns all rows from the left table and matching rows from the right; if there are no matches, the right columns will contain NULL.
- RIGHT JOIN (RIGHT OUTER JOIN) — the opposite, returns all from the right and matching from the left.
- FULL JOIN (FULL OUTER JOIN) — returns all rows from both tables, filling NULL where there are no matches.
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, returning orders with customer names.