LEFT JOIN Fundamentals
You'll learn how LEFT JOIN preserves all rows from the left table while bringing in matching data from the right table.
What Makes LEFT JOIN Different?
While INNER JOIN only returns rows where matches exist in both tables, LEFT JOIN keeps everything from the first (left) table and adds matching information from the second (right) table when available. If no match exists, the right table's columns appear as NULL.
Think of it like a guest list for an event: your main list (left table) includes everyone invited, and you're checking who RSVP'd (right table). Even if someone didn't RSVP, they still appear on your master list—just with blank RSVP information.
The Basic Syntax
SELECT columns
FROM left_table
LEFT JOIN right_table
ON left_table.key = right_table.key
The table after FROM is your "left" table—every row here will appear in results. The table after LEFT JOIN is your "right" table—only matching rows contribute data.
When to Use LEFT JOIN
Use LEFT JOIN when you need:
- All records from your primary table, regardless of matches
- To identify missing relationships (NULL values in right table columns)
- A complete picture with optional supporting details
For example, listing all customers and their orders—even customers who haven't ordered yet—requires LEFT JOIN. Those customers appear with NULL order information.
The Key Difference
Unlike INNER JOIN which excludes non-matching rows entirely, LEFT JOIN includes them with NULL placeholders. This makes LEFT JOIN essential for "show me everything from A, plus related B data if it exists" scenarios.
Key Takeaway: LEFT JOIN returns all rows from the left table plus matching rows from the right table; unmatched left rows still appear with NULL values for right table columns.