Junior — Middle
Can you list the main types of table joins in SQL and briefly describe their features?
sobes.tech AI
Answer from AI
Main types of JOINs in SQL:
- INNER JOIN — returns only those records that have matches in both tables.
- LEFT JOIN (LEFT OUTER JOIN) — returns all records from the left table and matching records from the right; if there are no matches, NULLs will appear on the right side.
- RIGHT JOIN (RIGHT OUTER JOIN) — conversely, returns all records from the right table and matching records from the left.
- FULL JOIN (FULL OUTER JOIN) — returns all records from both tables, with NULLs in the fields where there are no matches.
- CROSS JOIN — Cartesian product of two tables, returning all possible combinations of rows.
Example of INNER JOIN:
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;