The LEFT JOIN command retrieves all rows from the left table and the matching rows from the right table. If there is no match, NULL values are returned from the right side.
The following SQL will select all customers and any associated orders:
SELECT Customers.CustomerName, Orders.OrderID FROM Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID ORDER BY Customers.CustomerName; |
Note: The LEFT JOIN keyword retrieves all records from the left table (Customers), regardless of whether there are matches in the right table (Orders).