LEFT JOIN returns all rows from the left table and matching rows from the right table. If no match exists, columns from the right table contain NULL.
LEFT JOIN is essential when you need to retain all records from a primary dataset even when related information is missing.
Find all customers, including customers who have never placed an order.
SELECT
c.CustomerName,
o.OrderID
FROM Customers c
LEFT JOIN Orders o
ON c.CustomerID = o.CustomerID;
LEFT JOIN is commonly used for missing-data analysis, customer analysis, employee reporting, and data completeness checks.
- LEFT JOIN keeps all rows from the left table.
- Matching rows from the right table are included.
- Unmatched right-side values become NULL.
- It is useful for finding missing relationships.
- LEFT JOIN is also called LEFT OUTER JOIN.
What does LEFT JOIN return?
It returns all rows from the left table and matching rows from the right table.
What happens when there is no matching right-side record?
The left-side row is still returned and right-side columns contain NULL.