bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL LEFT JOIN

Sql Left Join

The LEFT JOIN returns all rows from the left table (table1), and only the matched rows from the right table (table2).

If there is no match in the right table, the result for the columns from the right table will be NULL.

The LEFT JOIN and LEFT OUTER JOIN keywords are equal - the OUTER keyword is optional.

LEFT JOIN Syntax

SELECT
column_name(s)
FROM
table1
LEFT JOIN
table2
ON
table1.column_name
=
 table2.column_name
;

Note

The syntax combines two tables based on a related column , and the ON keyword is used to specify the matching condition.

Demo Database

Below is a selection from the "Customers" table:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la Constitución 2222México D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico

And a selection from the "Orders" table:

OrderIDCustomerIDEmployeeIDOrderDateShipperID
10308271996-09-183
103093731996-09-191
103107781996-09-202

Here we see that the related column between the two tables above, is the "CustomerID" column.

Previous

SQL INNER JOIN

Next

SQL RIGHT JOIN