← Files SQL CopilotARCHIVED FILE

skills/debug-sql-results/SKILL.md

1.64 KB · Nov 27, 2026 · 19:07 UTC

↓ Download file

See the change to this file →

---
name: debug-sql-results
description: Find why a query returns wrong totals, too many rows, missing rows or unexpected NULLs.
---

# Debug Sql Results

**Trigger:** Find why a query returns wrong totals, too many rows, missing rows or unexpected NULLs.

## Workflow
1. Record the expected output and an observed mismatch (count, amount, key, date range, example order or entity).
2. Form competing hypotheses: row multiplication, late WHERE filters on LEFT JOIN, mismatched keys, NULL handling, timezone boundaries, floating division or dedup selection.
3. Generate minimal probe queries for each hypothesis: counts by key after each stage, unmatched keys, before/after aggregates, null group counts.
4. Prefer root-cause corrections: filter/dedup a many-side before join, restore missing rows or adjust grouping; retain business semantics.
5. Show expected changes and a reconciliation protocol, keeping observed results separate from assumptions.

## Critical standard
DISTINCT is not an acceptable default fix for fanout; a syntactically successful query may still be wrong.

## Evidence and execution
Only say "executed", "passed", "observed", "optimized" or "deployed" when a connected tool returned evidence for that claim. An SQL draft, a textual review, or local fixture proof alone is not production validation. Never ask the user to paste passwords or raw confidential records.

## Supporting references
- Read `../../references/debugging-playbook.md` when relevant.
- Read `../../references/joins-and-fanout.md` when relevant.
- Read `../../references/reconciliation.md` when relevant.

## Return
Hypothesis table, targeted probes, minimal fix and expected checks.

SHA-256: a408c42c5873c1cb159ac913260be70c91a7d281977b564a23d1cbae5ad7b72d