SQL · Queries that survive scale

What is the difference between INNER JOIN and LEFT JOIN?

Mediuminner joinleft joinnullsUpdated Oct 2026
Quiz this track

Short answer

INNER JOIN drops rows without a match. LEFT JOIN keeps every row from the left table and fills right-side columns with NULL where no match exists.

The difference is row preservation. An INNER JOIN returns only pairs that satisfy the condition. A LEFT JOIN returns every row from the left input at least once, adding NULLs for right-side columns when no match is found.

sql
SELECT c.id, c.email, o.id AS order_id
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.id IS NULL;
This anti-join finds customers with no orders. The WHERE condition intentionally removes matched rows.

Row counts and aggregates

  • LEFT JOIN can increase row count when the right side has multiple matches
  • COUNT(*) counts preserved rows, including those with no match
  • COUNT(o.id) ignores NULLs and counts only actual matches
  • A filter on the right table in WHERE can turn a LEFT JOIN into an effective INNER JOIN

To filter the right side while preserving unmatched left rows, put the condition in ON rather than WHERE. A WHERE condition such as o.status = 'paid' removes the NULL-extended rows produced for unmatched customers.

A LEFT JOIN is not automatically slower than INNER JOIN, but it gives the optimizer less freedom to reorder or eliminate the preserved side. Use the weakest join that expresses the requirement.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1How do you find rows in one table with no match in another?
  2. 2Why does a WHERE filter on the right table behave differently from an ON filter?
  3. 3What is the difference between COUNT(*) and COUNT(column) after a LEFT JOIN?
  4. 4Can a LEFT JOIN return more rows than the left table has?

Say it in the interview

An INNER JOIN returns only rows that match on both sides. A LEFT JOIN keeps every row from the left side and fills the right side with NULLs when there is no match. I use LEFT JOIN for optional relationships and anti-join patterns. The subtle part is filtering the right table: a WHERE predicate removes unmatched rows, while the same predicate in ON preserves them.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live SQL mock interview and get scored feedback on depth, clarity and confidence.