Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

LEFT JOIN

LEFT JOIN

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:

Example

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).