SQL – LEFT JOIN
Keep all rows from the left table and fill in NULLs for non-matching rows in the right table.
Table of Contents
LEFT JOIN (also called LEFT OUTER JOIN) keeps every row from the left table, regardless of whether a matching row exists in the right table. When there is no match in the right table, the right-side columns are filled with NULL. This is essential when you want to find records that are missing related data — e.g., students who have never enrolled in any course.
LEFT JOIN vs INNER JOIN
| Student | Enrollment | INNER | LEFT |
|---|---|---|---|
| Aria | SQL, Python | ✅ | ✅ |
| Ben | Web Design | ✅ | ✅ |
| Zara | (none) | ❌ | ✅ (NULLs) |
Try It Yourself — Interactive SQL Editor
Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.
Key Points
- LEFT JOIN preserves every row from the left table
- NULLs appear in right-side columns when there is no match
- WHERE right_col IS NULL finds rows with no match (anti-join)
- Table order matters: left table drives the result
Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.
In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.