SQL · easy

Explain the difference between INNER, LEFT, and FULL OUTER JOIN.

Asked in Data Analyst interviews, in the SQL round.

Short answer

INNER = matches only; LEFT = all left + matched right; FULL = all rows both sides.

How to answer it

Say what each one keeps.

Then show you know when each one is the right choice:

-- customers who have never ordered: LEFT JOIN, then keep the NULL side
SELECT c.customer_id
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
WHERE o.order_id IS NULL;

The follow-up interviewers like: put a condition on the right table in WHERE and a LEFT JOIN turns back into an INNER JOIN, because the NULL rows fail the filter. Conditions that should preserve unmatched rows belong in the ON clause. Also mention that a join on a non-unique key fans rows out, so COUNT(*) after a join counts matches, not customers.

Related questions

Practice this for real