AI joined your tables and inflated the total? Check keys and row grain
Use fictional orders and tags to detect join multiplication and reconcile the total against original orders.
Define what each row represents
A fictional order table has two rows: customer C’s order O1 is 20 yuan and O2 is 30 yuan. A fictional tag table has three different tags for customer C. Each order row is an order; each tag row is a customer tag. An inner join on customer ID matches each order to three tags, producing 2×3=6 rows. This hand-worked example is not an observed model or business result.
Reconcile against the original table
The original orders total 20+30=50 yuan. Each order appears three times after the join, so summing all six rows gives 150 yuan and is not the true order total. The rows are not necessarily wrong: six combinations may be intended when listing each order with each tag. For order totals, return to order grain. Do not deduplicate by amount, since different orders can have the same amount.
Choose a join after checking relationships
Check missing join keys, how often each key occurs in both tables, and whether the intended business relationship is one-to-one, one-to-many or many-to-many. If orders need one customer-level attribute, derive a unique customer-grain table using an explicit business rule, then check order-ID uniqueness and compare row counts and totals before and after the join. Do not arbitrarily discard meaningful tags. pandas merge can validate key uniqueness: 1:1 checks both sides, 1:m the left and m:1 the right. m:m is accepted but performs no uniqueness check; inspect duplicate keys, match cardinality and output row counts yourself. Passing validation does not prove business rules or values are correct.
Ask AI to show checks instead of guessing
Try: “First explain each table’s grain, join keys and expected relationship. Show checks for duplicate and missing keys, row counts before and after, and order-ID-level reconciliation. Mark unclear business rules for confirmation; do not drop rows on your own.” Run with fictional data in isolation and retain actual output; inspect unmatched rows and null-key handling. For example, pandas can match null keys on both sides, which needs separate review. Do not provide unauthorized customer information to a tool.
Reference:pandas documentation: merge and join