SQLQuestion 12 of 14
How do you check a result is correct on large data?
Answer out loud or in your head first, then compare.
Answer
First I establish the unit of the result: one row per customer, order or day. Then I compare record counts and totals before and after the JOINs.
SQL
-- Does the report have one row per customer?
SELECT customer_id, COUNT(*)
FROM report
GROUP BY customer_id
HAVING COUNT(*) > 1;I check: NULLs, missing matches, duplicates, ties, empty sets, date boundaries and division by zero. I build a small data set with a hand-calculated result and compare a sample with the source system.
Pitfall: valid syntax and a fast plan don't prove business correctness. DISTINCT can hide a faulty JOIN instead of fixing it.
How did it go? Be honest — “Not yet” puts the question on your review list.