Class 35 of 58 • Relational Joins & Set Operations

SQL LEFT OUTER JOIN: Preserving Left Table Rows & Finding Mismatches

The LEFT OUTER JOIN (commonly written as LEFT JOIN) returns all rows from the left table (Table A), regardless of whether a matching record exists in the right table (Table B). If a match exists in Table B, its column values are returned; if no match exists, the database supplies NULL for all columns of Table B.


Standard LEFT JOIN Syntax

SELECT a.column1, b.column2
FROM table_a a
LEFT JOIN table_b b ON a.key = b.key;

Hands-on Query: Listing All Students (Even Unassigned Ones)

-- Left Join guarantees EVERY student appears in the report
SELECT 
    s.student_id,
    s.first_name,
    COALESCE(d.dept_name, 'Unassigned') AS department,
    s.gpa
FROM students s
LEFT JOIN departments d ON s.dept_id = d.dept_id;
student_id first_name department gpa
1 Aman Engineering 3.85
2 Pooja Business 3.92
3 Rohan Engineering 3.75
4 Vikram Unassigned (NULL) 3.42

Finding Unmatched Records (The Left Anti-Join Pattern)

A common interview question: "Find all students who have not yet been assigned to any department":

SELECT s.student_id, s.first_name
FROM students s
LEFT JOIN departments d ON s.dept_id = d.dept_id
WHERE d.dept_id IS NULL; -- Filters only rows with no parent match!

Next, let us explore the mirror opposite: SQL RIGHT OUTER JOIN!


Frequently Asked Questions (FAQ)

There is no difference! In standard SQL, the keyword 'OUTER' is optional; 'LEFT JOIN' and 'LEFT OUTER JOIN' are 100% synonymous.

Perform a LEFT JOIN and add a WHERE condition checking for NULL in the right table's primary key: WHERE right_table.id IS NULL.

The database automatically populates NULL across all columns of the right table for that row.

Next Step in Your SQL Database Learning Path:

Proceed to the next class in sequence to build production mastery of relational database architecture.

Continue to Class 36: RIGHT JOIN → Previous: ← INNER JOIN | Full Syllabus


Related SQL Masterclass Lessons & Recommended Next Topics

INNER JOIN vs LEFT JOIN →

Understanding when to drop unmatched records vs keep them.

Detecting Missing Records →

Using LEFT JOIN ... WHERE right_table.id IS NULL to find orphans.

RIGHT OUTER JOIN →

Mirror counterpart to the left outer join.

FULL OUTER JOIN →

Combining left and right outer join results.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!