LESSON 04 / 24·2 min readFoundation

Why does a LEFT JOIN behave like an INNER JOIN?

01 Understand02 Recall03 Prepare

Understand the concept

A LEFT JOIN preserves left-side rows by filling unmatched right-side columns with NULL. A later WHERE condition can remove those rows if it requires a right-side value to match. This makes the final result look like an inner join even though the join itself was outer.

Important ideas

  • A WHERE condition on the right table can reject the NULL unmatched rows.

  • Put the condition in ON when it should limit matches but preserve left rows.

  • Example: keep every employee, but join only their approved leave records.

  • Move a right-side filter into ON only when the requirement is to limit matches while preserving all left rows.

Work through the example

SQL
SELECT e.id, l.id AS approved_leave_id
FROM employees e
LEFT JOIN leaves l
  ON l.employee_id = e.id AND l.status = 'approved';
  • Employees with no approved leave still appear with a NULL leave ID. Putting l.status = 'approved' in WHERE would remove those unmatched rows.
PAUSE & RECALL

Can you explain it without the notes?

Why does a LEFT JOIN behave like an INNER JOIN?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

A LEFT JOIN preserves left-side rows by filling unmatched right-side columns with NULL. A later WHERE condition can remove those rows if it requires a right-side value to match. This makes the final result look like an inner join even though the join itself was outer.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • Explain the difference between filtering matching partners and filtering final result rows.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: How should I compare NULL values?

Adapted from 05_SQL_POSTGRESQL.md · “Why does a LEFT JOIN behave like an INNER JOIN?”. Examples are study fragments; framework behavior can depend on your version.