LEFT JOIN (or LEFT OUTER JOIN) renders ALL records from the table on the left side (Table 1) and all matching records of the table on the right side (Table 2). In a LEFT JOIN, records that do not have corresponding data from the right table will show ‘NULL’ values from columns/fields selected from the right table.
NOTE: LEFT JOIN is very similar to RIGHT JOIN. The difference has to do with the table positioning in relation to the query. The ‘left’ table is always the table referred to in the FROM clause. The ‘right’ table is the table used after the JOIN clause and the matching column in each table is what binds the tables together.
LEFT JOIN Syntax:
LEFT JOIN Example:
LEFT JOIN Query:
Notice how the bottom 2 rows render ‘NULL’ results from the ‘Customers’ table on the bottom right of the result set. The result set outputs this way because of the positioning of the tables in the query using the LEFT JOIN. This will list ALL records from the ‘Address’ table, whether they have customer information tied to the address or not. For the two records/row that do not, the information from the ‘Customers’ table outputs ‘NULL’ values.
This blog post is part of our SQL series:
Stephanie is a big time math nerd, avid snowboarder, and overall winter lover. She enjoys the torture of running and traveling to work Ragnar Relay races. From shredding the gnar to getting far too invested in murder/crime documentaries, you'll also find her petting all the doggos. She was an employee of PDQ.