Analysis prompts
Analysis prompt

Write a SQL query I can trust

You need to pull data and want a query that's correct, not just one that runs.

Works best in: Claude

Write me a SQL query for this question. Show your work so I can trust it.

The question:
{{what I'm trying to answer}}

Schema (paste relevant tables, columns, types):
{{your schema}}

Notes:
- DB: {{Postgres / MySQL / Snowflake / etc.}}
- Anything weird: {{soft deletes, timezone gotchas, multi-tenancy fields, etc.}}

Output:
1. **The query**
2. **What it does step by step** — explain each CTE / join in plain language
3. **Edge cases** — what happens with NULLs? duplicates? rows missing in joined tables?
4. **What I should sanity-check** — a row count, an aggregate, or a known-correct example to verify the query
5. **What it does NOT answer** — common follow-up questions where this query would mislead

Don't optimize prematurely. Correctness first, performance only if relevant.
·Open in·Share
SQLqueriesdata

More analysis prompts

All analysis prompts