Part 2 of 5 · 1 min read
Inner join
Keeping only rows that match on both sides.
Think of matching socks pulled from a laundry basket. Only the socks that find a partner get kept. Every unmatched sock is set aside and left out of the result.
In plain words: an inner join returns only the rows where the join condition matches on both sides. A customer with no orders produces no row at all in an inner join between customers and orders. An order whose customer_id does not match any customer, which should not happen if the foreign key is enforced, would also be dropped.
A worked example. Listing every customer alongside their orders drops any customer who has never placed one.
The key lines.
SELECT c.full_name, o.order_id
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id;
Inner join
An inner join returns only the rows where the join condition is satisfied on both sides. A row with no match on the other side does not appear in the result at all.
Example: a customer who has placed zero orders produces zero rows in an inner join against orders, not one row with empty order columns.