Matching rows only
SELECT o.order_id, c.name
FROM orders o
INNER JOIN customers c ON c.customer_id = o.customer_id;
INNER is the default, so plain JOIN means the same thing. Only rows with a match on both sides appear.
What disappears
Two categories vanish silently:
- Customers with no orders
- Orders whose
customer_idmatches no customer (orphans, often from bad data)
Neither produces a warning. A report that quietly omits customers who have not ordered is a classic inner-join defect.
Checking for loss
Compare counts:
SELECT COUNT(*) FROM orders; -- 1000
SELECT COUNT(*) FROM orders o
JOIN customers c ON c.customer_id = o.customer_id; -- 987
Thirteen orders reference a customer that does not exist. Worth knowing before you publish a revenue figure.
Multiple tables
FROM orders o
JOIN customers c ON c.customer_id = o.customer_id
JOIN regions r ON r.region_id = c.region_id
Joins evaluate left to right, each operating on the accumulated result.