AnalystPracticeGuides
DashboardSign up

INNER JOIN vs LEFT JOIN: what's the difference?

INNER JOIN returns only the rows that have a match in both tables. LEFT JOIN returns every row from the left table, and fills the columns from the right table with NULL where there is no match. Use LEFT JOIN when you must not lose rows, for example customers who haven't ordered yet.

Watch it solved. Task 5: find missing rows with LEFT JOIN, from 3:47, in our video “Data Analyst Interview Questions and Answers: 10 SQL + Excel Tasks, Solved”. Pressing play loads the video from YouTube (privacy). Open on YouTube

Quick comparison

INNER JOINLEFT JOIN
Rows from the left table without a matchDroppedKept, with NULLs
Typical useOrders with their product detailsAll customers, with their orders if they have any
Find rows without a matchNot possibleWHERE right_table.id IS NULL

What do the two queries return?

Three customers: Ana, Ben and Cara. Only Ana and Ben have orders.

SELECT c.name, o.id
FROM customers c
INNER JOIN orders o ON o.customer_id = c.id;

Returns Ana's and Ben's orders. Cara disappears.

SELECT c.name, o.id
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id;

Returns the same rows plus one row for Cara, with NULL as the order id.

How do you find customers who never ordered?

This is one of the most common SQL interview questions:

SELECT c.name
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.id IS NULL;

Why does my LEFT JOIN behave like an INNER JOIN?

Because a filter on the right table in WHERE removes the NULL rows again. This query loses every customer without a 2026 order:

… LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.order_date >= '2026-01-01';

Move the condition into ON to keep all customers:

… LEFT JOIN orders o ON o.customer_id = c.id AND o.order_date >= '2026-01-01';

Why are my totals too high after a join?

If the key on the right side is not unique, every left row is repeated once per match. Summing a column from the left table after such a join counts it several times. Check with SELECT key, COUNT(*) … GROUP BY key HAVING COUNT(*) > 1 before you join, or aggregate the right table first.

A related trap: after a LEFT JOIN, COUNT(*) counts Cara as 1, while COUNT(o.id) correctly counts her 0 orders.

Try it yourself. Run these joins against a real database in your browser and get instant feedback.
Practise JOIN Practise LEFT JOIN

← All free guides