Solve “Customers who never ordered”

Free. Runs in your browser, no install.

SQL · Basics & Joins

INNER JOIN vs LEFT JOIN

Easyjoinsinner joinleft join

Interview question

What is the difference between INNER JOIN and LEFT JOIN?

How to answer

The short answer

INNER JOIN returns only rows that have a matching record in both tables.

LEFT JOIN returns all rows from the left table, plus matching rows from the right table. If there is no match, right-side columns become NULL.

SQL
SELECT *
FROM customers c
INNER JOIN orders o
    ON c.id = o.customer_id;

Only customers who have orders are returned.

SQL
SELECT *
FROM customers c
LEFT JOIN orders o
    ON c.id = o.customer_id;

All customers are returned, including customers with no orders.

Interview shortcut

> INNER = matching rows only > LEFT = everything from left + matches from right

Lock it in with a real drill

You remember an answer longer once you have used it. Try a hands-on problem on this concept.

Open related drill