What is an INNER JOIN?
SQLLevel: FoundationJOINs Basics
What is an INNER JOIN?
Hints
- Write the join keys and relationship cardinality.
- What happens to duplicates and unmatched rows? Check WHERE versus ON.
Answer
An INNER JOIN returns rows that have matching values in both tables. Rows without a match in either table are excluded.
SELECT o.order_id, c.name, o.total
FROM orders o
INNER JOIN customers c ON o.customer_id = c.customer_id;
This only returns orders that have a corresponding customer, and customers that appear in orders. If a customer has no orders, they won't appear. If an order somehow has no matching customer (which shouldn't happen with FK constraints), it won't appear either.
Source and licence: SQL Interview Questions — Arda Kocadoru · MIT