One Order Can Become Three Rows After a Join

Conceptual desk scene with a notebook, a pressed leaf and blank cards beside a laptop.
Conceptual illustration created with AI; not a research result or laboratory photograph.

An orders table contains one row per order. An items table contains one row per item. Join them by order ID and an order containing three items can appear three times without the database making a mistake.

The PostgreSQL join tutorial describes joins as combinations of rows that satisfy a matching condition. The number of matches matters as much as the name of the matching field.

Imagine order A has an order-level shipping charge of 6 and three item rows. A joined result repeats that 6 beside each item. Summing the repeated column gives 18, even though the fictional order has only one shipping charge.

Check the unit of a row

Before adding totals, write down what one row represents in each input and in the output. Inspect the matched rows for a single identifier whose expected result you know. Count matches per key and look for unexpected multiplicity.

Do not repair the example by removing every duplicate-looking row: two legitimate items can share a description or price. Choose an aggregation appropriate to order-level charges and item-level quantities, keeping their different levels explicit.

A useful output note says “one row per order item” rather than merely “merged data.” That small label warns the next analyst that some order-level values are repeated context, not additional amounts to total.

Editorial illustration from this site’s image library; not documentary evidence of the example or object discussed.