LEFT JOIN keyword returns all rows from the left table (TABLE1), with the matching rows in the right table (TABLE2).
syntax
SELECT COLUMN(s) FROM TABLE_NAME1 FULL OUTER JOIN TABLE_NAME2 ON TABLE_NAME1.COLUMN=TABLE_NAME1.COLUMN
Demo Database (Customers Table)
CustomerID | CustomerName | ContactName | Address | City | PostalCode | Country |
---|---|---|---|---|---|---|
1 | Alfreds Futterkiste | Maria Anders | Obere Str. 57 | Berlin | 12209 | Germany |
2 | Ana Trujillo Emparedados y helados | Ana Trujillo | Avda. de la Constitucion 2222 | Mexico D.F. | 05021 | Mexico |
3 | Antonio Moreno Taqueria | Antonio Moreno | Mataderos 2312 | Mexico D.F. | 05023 | Mexico |
Demo Database (Orders Table)
OrderID | CustomerID | EmployeeID | OrderDate | ShipperID |
---|---|---|---|---|
10248 | 90 | 5 | 1996-07-04 | 3 |
10249 | 81 | 6 | 1996-07-05 | 1 |
10250 | 34 | 4 | 1996-07-08 | 2 |
example
SELECT Customers.CustomerName, Orders.OrderID FROM Customers FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID ORDER BY Customers.CustomerName;
Above Statement selects all customers, and all orders with FULL OUTER JOIN..
CustomerName | OrderID |
---|---|
Alfreds Futterkiste | |
Ana Trujillo Emparedados y helados | 10308 |
Antonio Moreno Taqueria | |
Around the Horn |