sql-correctness-reviewlisted
Install: claude install-skill vermapragya/analytics-skill
# SQL Correctness Review
## When to use this skill
Use when a query might return **wrong results** — regardless of how fast it runs. Triggers:
- "These numbers look too high/low"
- "Revenue is double-counting"
- "Why do I have duplicate rows?"
- "This join is exploding"
- "Check the logic of this query"
- Two reports disagree on the same metric
Routing: performance/anti-patterns → `sql-query-review`. Bad data *in the table* (not the query) → `data-quality-audit`. The first job here is deciding which of the two it is.
## Required inputs
| Input | Why it matters |
|---|---|
| Query text | The suspect |
| Expected output grain | "One row per X" — every check is relative to this |
| Key relationships | Which joins are 1:1 vs 1:N (or what you *believe* they are) |
| A reconciliation anchor | A number you trust (row count, total from a source system) to diff against |
| Access to run SQL | Evidence queries are the core of this skill |
## The five bug classes
| # | Class | Symptom | Canonical cause |
|---|---|---|---|
| 1 | Duplicates | Row count too high; metrics inflated | Source table grain misunderstood; missing dedup |
| 2 | Join fanout | Totals inflate after a join | Joining on a partial key (1:N or N:M treated as 1:1) |
| 3 | Wrong join type | Rows silently disappear | INNER where LEFT intended; WHERE on a LEFT join's right table |
| 4 | NULL handling | Rows vanish or comparisons silently fail | NOT IN + NULL; `col != 'x'` dropping NULLs; NULL join keys |
| 5 | CASE i