What is a SQL join?
Definition
A join lets a query combine related records, such as orders and customers matched by customer ID. The condition defines which rows are paired.
An inner join returns matching pairs. A left join also retains rows from the left table without a match. If one record matches several others, the join can produce several result rows.
Why it matters
Joins often sit behind a surprising change in a report’s totals. A table of customers may have one row per customer, while a table of orders has several rows for each customer. Combining them changes the number of rows available to a later calculation, so the resulting total needs to be interpreted at the right level.
Before trusting a joined result, check the relationship:
- Identify the fields used to match records and whether their values are unique.
- Decide what should happen to records without a match.
- Compare row counts and a known total before and after the join.
Use a small example where the expected matches are easy to inspect. That can reveal a problem more clearly than examining a large final chart.