What Is SQL LEFT JOIN?
The SQL LEFT JOIN keyword returns all records from the left table (the table listed first in the FROM clause) and the matched records from the right table. When a row in the left table has no corresponding match in the right table, the columns from the right table are filled with NULL.
Think of it like taking attendance — you list every student in the class (left table), and if they submitted an assignment (right table), you note their score. Students who did not submit anything still appear on the list but with a blank score. If you have completed the previous chapter on INNER JOIN, you know that INNER JOIN would exclude students without submissions entirely.
SQL LEFT JOIN Syntax
Here is the basic SQL LEFT JOIN syntax:
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
The ON clause specifies the matching condition between the two tables, just like with INNER JOIN. The difference is in what gets returned when there is no match.
💡 LEFT JOIN vs LEFT OUTER JOIN
LEFT JOIN and LEFT OUTER JOIN are identical in SQL. Most developers use the shorter form LEFT JOIN for readability.
Sample Tables
We will continue using the Customers and Orders tables from our SQL Tutorial course.
+----+----------------+-----------+---------+
| ID | CustomerName | City | Country |
+----+----------------+-----------+---------+
| 1 | Rahul Sharma | Mumbai | India |
| 2 | Sarah Johnson | New York | USA |
| 3 | Amit Patel | Delhi | India |
| 4 | Lisa Chen | Singapore | SG |
| 5 | David Brown | London | UK |
+----+----------------+-----------+---------+
+----+------------+------------+--------+---------+
| ID | CustomerID | OrderDate | Amount | Status |
+----+------------+------------+--------+---------+
| 1 | 1 | 2026-01-15 | 250.00 | Shipped |
| 2 | 2 | 2026-01-18 | 430.00 | Pending |
| 3 | 1 | 2026-02-01 | 180.00 | Shipped |
| 4 | 3 | 2026-02-10 | 520.00 | Shipped |
| 5 | 4 | 2026-03-05 | 310.00 | Pending |
+----+------------+------------+--------+---------+
Remember, Customer ID 5 (David Brown) has no orders. This is the perfect scenario to see how LEFT JOIN differs from INNER JOIN.
SQL LEFT JOIN Example
Let us write a SQL LEFT JOIN example to list all customers and their order amounts, including customers with no orders:
SELECT c.CustomerName, o.Amount, o.OrderDate
FROM Customers AS c
LEFT JOIN Orders AS o
ON c.ID = o.CustomerID;
+----------------+--------+------------+ | CustomerName | Amount | OrderDate | +----------------+--------+------------+ | Rahul Sharma | 250.00 | 2026-01-15 | | Rahul Sharma | 180.00 | 2026-02-01 | | Sarah Johnson | 430.00 | 2026-01-18 | | Amit Patel | 520.00 | 2026-02-10 | | Lisa Chen | 310.00 | 2026-03-05 | | David Brown | NULL | NULL | +----------------+--------+------------+
Notice the last row — David Brown appears with NULL values for Amount and OrderDate because he has no matching order. With INNER JOIN, this row would have been excluded completely.
SQL LEFT JOIN NULL — Finding Unmatched Records
One of the most powerful uses of LEFT JOIN is finding records in the left table that have no match in the right table. You can do this by adding a WHERE clause that checks for NULL values:
SELECT c.CustomerName, c.City
FROM Customers AS c
LEFT JOIN Orders AS o
ON c.ID = o.CustomerID
WHERE o.ID IS NULL;
+----------------+-----------+ | CustomerName | City | +----------------+-----------+ | David Brown | London | +----------------+-----------+
This pattern is extremely useful for data quality checks — finding orphaned records, inactive users, products without sales, and more. You learned about IS NULL in Chapter 9: SQL NULL Values.
LEFT JOIN vs INNER JOIN
Understanding when to use LEFT JOIN vs INNER JOIN is a critical skill. Here is a comparison:
| Feature | INNER JOIN | LEFT JOIN |
|---|---|---|
| Left table rows | Only matched rows | All rows (matched + unmatched) |
| Right table rows | Only matched rows | Matched rows only; NULL for unmatched |
| NULL in result | No NULLs from join | NULLs appear for unmatched right rows |
| Use when | You need only records that exist in both tables | You need all records from one table, even without matches |
| Common use case | Customers who placed orders | All customers, including those without orders |
💡 Quick Decision Guide
Ask yourself: “Do I need ALL rows from the left table, even if they have no match?” If yes, use LEFT JOIN. If no, use INNER JOIN.
SQL LEFT JOIN with Aggregation
You can combine LEFT JOIN with aggregate functions like COUNT and SUM to get summary data for all records:
SELECT c.CustomerName, COUNT(o.ID) AS TotalOrders
FROM Customers AS c
LEFT JOIN Orders AS o
ON c.ID = o.CustomerID
GROUP BY c.CustomerName;
+----------------+-------------+ | CustomerName | TotalOrders | +----------------+-------------+ | Rahul Sharma | 2 | | Sarah Johnson | 1 | | Amit Patel | 1 | | Lisa Chen | 1 | | David Brown | 0 | +----------------+-------------+
David Brown shows 0 orders because COUNT does not count NULL values. This is a common reporting pattern — showing all entities with their activity count, even if zero. You will learn more about grouping in Chapter 25: SQL GROUP BY.
⚠️ Watch Out: WHERE vs ON in LEFT JOIN
Placing a filter condition in the WHERE clause after a LEFT JOIN can convert it into an INNER JOIN if the filter excludes NULL values. To preserve all left rows while filtering the right table, place the condition in the ON clause instead.
If you are building reports with SQL-powered data, check out our Google Sheets Dashboard Templates on NextGenTemplates for ready-made business analytics.
📺 Visit our YouTube channel @NeoTechNavigators for step-by-step video tutorials and dashboard demos on this topic.
🧪 Try It Yourself
Write a query to display every customer’s name and their total order amount. Customers with no orders should show 0 as the total. Use LEFT JOIN with the COALESCE function.
SELECT c.CustomerName, COALESCE(SUM(o.Amount), 0) AS TotalSpent
FROM Customers AS c
LEFT JOIN Orders AS o
ON c.ID = o.CustomerID
GROUP BY c.CustomerName;
Expected Output:
+----------------+------------+ | CustomerName | TotalSpent | +----------------+------------+ | Rahul Sharma | 430.00 | | Sarah Johnson | 430.00 | | Amit Patel | 520.00 | | Lisa Chen | 310.00 | | David Brown | 0 | +----------------+------------+
Excellent! You combined LEFT JOIN with SUM and COALESCE to handle NULL values gracefully.
📝 What You Learned in This Chapter
LEFT JOIN— returns all rows from the left table plus matching rows from the right table- Unmatched rows in the right table produce
NULLvalues in the result LEFT JOINandLEFT OUTER JOINare identical- Use
WHERE column IS NULLafter LEFT JOIN to find unmatched records - LEFT JOIN with
COUNTorSUMgives activity summaries including zero-activity records - Be careful placing filters in WHERE vs ON — it changes the result set
Frequently Asked Questions
NULL values for all right-table columns.LEFT JOIN and LEFT OUTER JOIN produce exactly the same result. The keyword OUTER is optional and most SQL developers omit it for brevity.NULL for any columns from the right table where no match exists. Use INNER JOIN when you need only matched data; use LEFT JOIN when you need all records from one table.WHERE clause that checks if a column from the right table IS NULL. For example: WHERE orders.ID IS NULL returns only customers who have no orders. This is one of the most common uses of LEFT JOIN in real-world applications.GROUP BY or DISTINCT to consolidate duplicates when needed.📖 Chapter 22 of 30 — SQL Tutorial on Neotech Navigators


