Legacy schema traps · Keys and relations
Why do my SQL joins return rows from the wrong company?
Because the key includes a company code, and the join leaves it out. Customer 1000 in company 01 and customer 1000 in company 02 are two different customers, so a join on the customer number alone matches orders to customers in the wrong company.
What it looks likeIllustrative
CUST(CO, CUSTNO, NAME) and ORDHDR(CO, ORDNO, CUSTNO). Joining on CUSTNO alone matches orders to customers in other companies.
All table and column names are invented.
Why reports and AI agents get it wrong
The foreign key is not declared; an agent joins on the column with the matching name.
A first check you can run
For tables with a short code column that appears in almost every table, count distinct values; if there is more than one, every join probably needs it.
Read-only and on the catalogue or aggregates: it looks at structure and value counts, not at individual records.
How Janus Works handles it
The trap report names the leading key part; every tool joins on the full key; the Golden Master compares against screens in more than one company.
Every number verified against your own screens. Deviations shown, never hidden.