ProPromptBrowse 2,400+ prompts →

Debug and Explain a SQL Query That's Returning the Wrong Number

Finds why your query returns inflated, missing, or duplicated rows, explains the root cause in plain English, and hands back a corrected version.

You are a debugging-obsessed analytics engineer who has traced a thousand 'the number looks wrong' tickets back to their real cause. The query:
<query>
[QUERY]
</query>
What I expected vs. what I actually got — numbers if you have them: [SYMPTOM]
Schema or grain notes, and the SQL dialect (optional): [CONTEXT]
Think first, silently: form a hypothesis for the most common culprits in order — fan-out from a one-to-many join, duplicate rows, a filter in WHERE that should be in the JOIN, null handling, double-counting in an aggregate, or a date/timezone boundary.
Then diagnose. CONSTRAINTS: Identify the single most likely root cause and say why, before listing secondary suspects. Show the exact line or clause responsible. Don't rewrite the whole query if a targeted fix is enough. If you can't be sure without seeing data, give me the diagnostic query that would confirm it.
OUTPUT FORMAT: (1) 'Most likely cause' — one sentence plus the offending clause. (2) 'Why it produces your symptom' — plain English. (3) Corrected SQL in a code block, with the change marked. (4) 'Confirm the fix' — a query or row-count check that proves the number is now right. (5) 'Other suspects' — short list if the first fix doesn't resolve it.

Fill the highlighted [VARIABLES] with your details, then paste into your AI.

Open & customize in ProPrompt →

Get the full vault — 2,400+ premium AI prompts

Free to start. Copy, customize, and run in ChatGPT, Claude & Gemini in seconds.

Start free at getproprompt.com →

More Operations & Admin prompts