datarekha
SQL Easy Asked at AmazonAsked at GoogleAsked at Microsoft

What is the difference between INNER JOIN, LEFT OUTER JOIN, and FULL OUTER JOIN?

The short answer

INNER JOIN returns only rows where the join condition matches in both tables. LEFT OUTER JOIN returns every row from the left table plus matching rows from the right, filling NULLs where there is no match. FULL OUTER JOIN returns all rows from both sides, with NULLs wherever one side has no match.

How to think about it

The question sounds basic, but interviewers care whether you can reason about row counts and NULLs — not just recite definitions. The best answer starts with a concrete use case: “I’d reach for LEFT JOIN when I want all customers whether or not they’ve ordered.”

Row behaviour at a glance

Join typeRows kept from ARows kept from B
INNERmatched onlymatched only
LEFT OUTERallmatched only
RIGHT OUTERmatched onlyall
FULL OUTERallall

Code example

-- orders may have a customer_id; customers may have no orders yet
SELECT c.name, o.order_id, o.amount
FROM customers c
LEFT JOIN orders o ON c.id = o.customer_id;
-- customers with no orders appear with NULL in order_id, amount
-- FULL OUTER JOIN: all customers and all orders, whether matched or not
SELECT c.name, o.order_id
FROM customers c
FULL OUTER JOIN orders o ON c.id = o.customer_id;
INNERLEFTFULL OUTER
Shaded area = rows returned. INNER keeps only the overlap; LEFT keeps all of A; FULL OUTER keeps everything.

See it in action

Run the query below. Notice that customer “Dana” (no orders) disappears with INNER but stays with LEFT. Change INNER JOIN to LEFT JOIN and watch the difference.

What to mention in an interview

  • FULL OUTER JOIN is not supported in MySQL; use LEFT JOIN UNION ALL RIGHT JOIN WHERE left.id IS NULL.
  • RIGHT JOIN is just a LEFT JOIN with tables swapped — most style guides prefer LEFT for readability.
  • Lead with the use case: “I’d reach for LEFT JOIN when I want all customers, whether they’ve ordered or not.”
  • Always think about what happens to unmatched rows — that reasoning separates strong candidates.
Learn it properly LEFT, RIGHT, FULL

Keep practising

All SQL questions

Explore further

Skip to content