Stockertim Dictionary · Technology
SQL join
Also called JOIN clause, table join, joining tables
In short
An SQL operation that combines rows from two tables by matching values in shared columns, so facts stored separately can be reported together.
- Beginner
- Concept
- Checked
In detail
A join brings back together information that a relational design keeps apart. A payments table may hold only an account number; the accounts table holds the name and branch. JOIN accounts ON payments.account_no = accounts.account_no pairs each payment with its account, producing rows that carry columns from both tables.
The ON condition defines what counts as a match, usually equality between a foreign key and a primary key. Tables are often given short aliases, such as p and a, so that columns with the same name in both tables can be told apart: p.amount, a.branch. Several joins can be chained to reach a third or fourth table.
The type of join decides what happens to rows without a partner. An inner join, the default when only JOIN is written, keeps matched pairs and drops everything else. A left join keeps every row from the first table and fills the second table's columns with NULL where nothing matched. Right and full outer joins exist too, and a cross join pairs every row with every row, which is rarely wanted.
Joins are where most query errors begin. A key with duplicates on the wrong side multiplies rows; a key that differs in type or format matches nothing; an inner join where a left join was needed silently loses rows. A simple discipline catches most of these: count the rows before and after each join and explain any difference.
Worked example
A microfinance lender in Lusaka has 5,000 repayment rows and a borrowers table, and wants repayments with each borrower's branch.
- Write:
SELECT r.repayment_id, r.amount, b.branch FROM repayments AS r JOIN borrowers AS b ON r.borrower_id = b.borrower_id; - The result has 4,960 rows, so 5,000 − 4,960 = 40 repayments found no borrower.
- Those 40 rows are listed with a left join and sent to the data team.
The branch report is produced, with a note explaining the 40 unmatched repayments instead of losing them.
In practice
Analysts join tables in almost every report: transactions to customers, order lines to products, staff to departments. In spreadsheets the equivalent is a lookup column with XLOOKUP or VLOOKUP; in pandas it is the merge function. The row-count check before and after applies to all three.
Watch out
- A join that runs without error can still lose or duplicate rows; compare row counts and totals before and after.
- Joining on names or descriptions instead of codes invites mismatches from spelling and spacing.
Learn it properly
More lessons about sql join
Official sources
- The Government Data Quality Framework · UK Government Data Quality Hub
- The AQuA Book: guidance on producing quality analysis for government · HM Treasury
Facts last checked on 9 November 2026.
Education, not advice: the Stockertim Dictionary explains what terms mean. It never recommends buying or selling anything.