The latest in AI, every dayAI News

Code · August 2, 2026

Fix that slow or broken SQL query, with the why explained

Paste a slow or broken SQL query and get the exact diagnosis plus the fix, explained without jargon so you understand why it was happening.

That SQL query that takes too long or throws a cryptic error is almost never something you can fix by trial and error alone. This prompt gives you the exact diagnosis of what's wrong (index, join, data type) and the ready-to-run fix, explained without jargon.

For: ClaudeChatGPTClaude Code
Full prompt
Act as a senior database engineer specialized in SQL query optimization, who prioritizes the
minimal change needed to fix the problem and explains every decision in clear terms, without
unnecessary jargon.

I'm going to paste a SQL query that's slow or throwing an error. Your job is to diagnose the
exact cause and give me the fix, without inventing schema details I didn't give you.

Database engine: [E.G. PostgreSQL, MySQL, SQL Server, SQLite]
Current query: [PASTE THE FULL SQL QUERY HERE]
Structure of the tables involved (columns, types, indexes if you know them): [PASTE THE SCHEMA, OR WRITE "don't have it handy"]
What I expected to happen: [E.G. return this month's orders, run in under 1 second]
What actually happens: [E.G. it takes 30 seconds, throws "column ambiguous", returns duplicate rows]
Approximate table size (if you know it): [E.G. 2 million rows in "orders"]

Give me:
1. The exact cause of the problem (missing index, badly built join, unnecessary subquery,
   incompatible data type, etc.), in two or three clear sentences.
2. The corrected full query, ready to copy and run.
3. Why this fix works, explained like you'd explain it to me in person, without assuming I
   can read an execution plan.
4. If it's a performance problem, tell me if a new index would fix it more thoroughly (and
   the exact command to create it), separate from the fix to the query itself.
5. If there's schema information you don't have that would change the diagnosis, tell me
   instead of assuming and proposing a fix that might not apply.

Anti-hallucination rules: don't invent column, table, or index names I didn't give you. If
you need a schema detail you don't have, flag it as [data to verify] instead of assuming it.
Don't add schema changes (new columns, tables, triggers) unless I explicitly ask for them.
Short link: wandabuilds.ai/p/wNQp

Come back tomorrow for another, or see all prompts.