Audit intermediate Works with: Any AI

SQL Report Number Reconciliation Between Two Queries

Table output

Find why two queries disagree and which is right.

The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.

Rate this prompt

Loading ratingsโ€ฆ

Two queries should give the same number but do not. Query A: [QUERY_A]. Query B: [QUERY_B]. Results: [RESULTS]. Table descriptions: [TABLE_NOTES].

Walk through the logic in the order the database would: base tables, joins, filters, grouping and output. Mark where the two queries differ and what each difference does to the result: which rows each includes, join types, duplicates created by joins, filters on dates and status, time zones, NULL handling and aggregation level. Do not decide which number is right without the business definition; ask for it and suggest who owns it. Diagnostic queries in words: counts at each step, a list of keys present in one result and not the other (anti-joins), and a check for duplicates in the join key. Small examples: an order of 100 with 2 lines becomes 200 if summed after the join. Worked reconciliation: query A returns revenue by order date totalling 10,500 for March and query B uses the shipped date and returns 9,800; the difference of 700 comes from orders created on the 30th and 31st and shipped in April, found by grouping by both dates.

Return a table of differences with Likely effect and Test, and a recommended definition of the correct query, to be confirmed by the business owner. Publish the definition of the revenue date in the report title.

Fill in before use

Optional: type your details and the prompt above updates. Nothing is saved or sent.

Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.

Related prompts