GOVERNMENT JOBS · IT CAREERS · PRACTICAL GUIDES

Prevent Double Counting When Joining Two Tables

By JobJet · Published 12 October 2026 · 2 min read · AI-assisted guide

Illustration for Data Analytics
JobJetPrevent Double Counting When Joining Two TablesData Analytics · INSIGHT

Joining tables can change the number of rows in surprising ways. A total that was correct before a join may become inflated afterwards. The first defence is to understand what one row means in each table.

Map the relationship

Use a fictional orders table with one row per order and an items table with one row per product line. An order containing three products will match three item rows. After the join, the order’s delivery charge may appear three times.

Check a small example manually

Create order A with a delivery charge of 40 and two item lines. If you sum the delivery-charge column after joining, the result becomes 80 unless the calculation handles the repeated value. The join has not necessarily failed; the aggregation has used the wrong grain.

Aggregate at the appropriate level

Depending on the question, calculate item totals per order first, or calculate delivery totals directly from the orders table. Avoid removing duplicate-looking rows blindly: two identical product lines may be legitimate separate records.

Inspect unmatched records as well. A left join can preserve orders without items, while an inner join only retains matches. The correct choice depends on the question, not on which result looks cleaner.

Reconcile before reporting

Record row counts, unique order counts, and relevant totals before and after the join. Explain every expected change. Test an order with multiple items, one with no match, and a duplicate key.

Technical reference: PostgreSQL’s tutorial on joins. For your portfolio, include the small example and reconciliation notes alongside the query. A reviewer should see how you checked the result.


Created with AI assistance for JobJet. Illustrative exercises use fictional data; no employer outcomes are promised.

Explore JobJet Insight