A left join returns all rows from the left table, plus matching rows from the right table
A left join is a way to combine data from two tables in SQL. It keeps every row from the table on the left side of the join, and adds columns from the table on the right side whenever there's a match. If there's no match, the columns from the right table show as empty (NULL).
The key difference from other joins is that a left join never drops rows from your left table. If you're joining a customers table to an orders table with a left join, you'll see every customer in your results — even customers who have never placed an order. Those customers will have empty cells where the order information would go.
Key Takeaways
- A left join keeps all rows from the left table and adds matching data from the right table, leaving blanks where there's no match.
- Use a left join when you want to see everything from one table and add extra information from another table only when it exists.
- The order matters: LEFT JOIN table_b is different from RIGHT JOIN table_a because the "left" table is the one that keeps all its rows.
- Left joins are common for finding gaps — like customers with no orders, employees with no projects, or products with no sales.
When to use a left join instead of an inner join
An inner join returns only rows where both tables have a match. A left join returns all rows from the left table whether or not the right table has a match. Choose a left join when you need to keep rows that might not have a match.
For example: if you're running a report on all employees and their current projects, an inner join would hide employees who aren't assigned to any project. A left join shows all employees, with blank project columns for those without assignments. This matters if you're trying to find underutilized staff or track who needs work.
Another common case: you're analyzing customer behavior and want to see all customers alongside their purchase history. A left join shows every customer, including those who signed up but never bought anything. An inner join would only show customers who made at least one purchase, which would give you incomplete data about your customer base.
The basic syntax and how it works
The structure of a left join looks like this:
SELECT columns_you_want FROM left_table LEFT JOIN right_table ON left_table.key = right_table.key
The ON clause is the matching condition — it tells SQL which rows belong together. Usually this is a shared ID or code that exists in both tables. If a row in the left table has no match in the right table, SQL still includes that row in the results, but fills the right table's columns with NULL (empty).
Here's a concrete example. Say you have a customers table with customer_id and customer_name, and an orders table with order_id, customer_id, and order_total. This query returns every customer and their orders if they have any:
SELECT customers.customer_name, orders.order_id, orders.order_total FROM customers LEFT JOIN orders ON customers.customer_id = orders.customer_id
If customer 5 (Alice) has three orders, Alice appears three times in the results — once for each order. If customer 7 (Bob) has no orders, Bob appears once with NULL values in the order_id and order_total columns.
How left joins handle multiple matches
If one row in the left table matches multiple rows in the right table, the left join creates one result row for each match. This is important to understand because it can make your result set larger than you expect.
Using the customers and orders example: if Alice has three orders, the left join produces three rows for Alice — one for each order. This is correct behavior, but it means you can't just count rows to count customers. If you want to count unique customers, you'd need to use DISTINCT or GROUP BY.
This also matters for calculations. If you sum order_total without grouping by customer, you'll get the total across all rows, which includes Alice's orders three times. Grouping by customer_id first, then summing, gives you the total per customer.
Left join versus right join versus full outer join
A right join is the mirror image of a left join — it keeps all rows from the right table and adds matches from the left table. RIGHT JOIN table_b is the same as LEFT JOIN table_a if you swap the table order. Most SQL writers use left joins because it's easier to read the table order from top to bottom.
A full outer join keeps all rows from both tables. If a row in the left table has no match in the right table, it appears with NULL values for the right table's columns. If a row in the right table has no match in the left table, it appears with NULL values for the left table's columns. Full outer joins are less common because they can produce very large result sets and are harder to reason about.
In practice, left joins are the most common because they answer the question "show me everything from table A, and add information from table B when it exists." That's a natural way to think about combining data.
Common mistakes and how to avoid them
One frequent mistake is forgetting that the join order matters. LEFT JOIN is not the same as RIGHT JOIN — the table on the left of the join keyword is the one that keeps all its rows. If you write the wrong join type, you'll lose data you meant to keep.
Another mistake is using a WHERE clause that accidentally filters out the rows you wanted to keep. If you write WHERE right_table.column IS NOT NULL, you've turned your left join into an inner join because you're removing all rows where the right table had no match. If you need to filter the right table's data, do it in the ON clause instead of the WHERE clause.
A third mistake is joining on the wrong column. If you join on a column that isn't unique in the right table, you'll get multiple rows per left table row (which might be what you want, but often isn't). Always check that your join key actually identifies unique records in the right table, or at least understand what multiple matches mean for your analysis.
Frequently Asked Questions
What's the difference between LEFT JOIN and LEFT OUTER JOIN?
They're the same thing. LEFT OUTER JOIN is the full formal name, but most SQL writers just write LEFT JOIN. Different database systems (MySQL, PostgreSQL, SQL Server) all support both versions.
Why do I get NULL values in my results?
NULL appears when a row from the left table has no matching row in the right table. The left join keeps the left row anyway, but has nothing to fill in from the right table, so it uses NULL. This is normal and expected — it shows you which left table rows had no match.
Can I join more than two tables with left joins?
Yes. You can chain left joins: FROM table_a LEFT JOIN table_b ON ... LEFT JOIN table_c ON ... Each join adds another table's columns, keeping all rows from table_a and adding matches from table_b, then adding matches from table_c. The logic is the same — each join keeps all rows from the accumulated result so far.
How do I count unique records when a left join creates multiple rows?
Use GROUP BY on the left table's ID column, then use COUNT(DISTINCT left_table.id) or just COUNT(*) within each group. This collapses the multiple rows back to one row per left table record, so your counts are accurate.