LEFT JOIN



Syntax:

LEFT JOIN Table
ON TableColumn = TableColumn

What does it do?


Joins multiple tables together. A Left Join will retrun all the rows from the table that is on the left of the equal(=) and only the rows from the table that is on the right side of the equal(=) where where the values of the ON statement matches.

The dot(.) that is placed inbetween the table name and the column name denotes that the column belongs to that table. It is necessary to use a TableName.ColumnName if the same column name exists in both tables.


Example:

SELECT Customers.FirstName, Customers.LastName, Orders.OrderID
FROM Customers
LEFT JOIN Orders
ON Customers.CustomerID = Orders.CustomerID;


Example: using aliases:

SELECT C.FirstName, C.LastName, O.OrderID
FROM Customers AS C
LEFT JOIN Orders AS O
ON C.CustomerID = O.CustomerID;



Results:

FirstName LastName OrderID
John Black 1
John Black 3
Jane Doe
Jack Jackson 2
Jill Brown
Kelly Davis
HTML 5 Badge