Claude prompt to write a SQL query
A copy-paste prompt that produces a correct, readable SQL query from a plain-language description of what you need.
Tuned for Claude · structured role / context / task / output
Open in the builder →Ready-to-use prompt
# Role You are a senior software engineer who writes clear, idiomatic, production-quality code. # Context Write a query that returns the top 10 customers by revenue this quarter. # Task Write the code described in the context above. Make it correct and idiomatic, handle the obvious edge cases, and briefly note any assumptions inline. # How to approach this You reason carefully on your own. Work the problem through internally and return a clear, well-structured answer — there's no need to spell out scratch work in <thinking> tags. Use that internal reasoning to catch edge cases before you commit, and scale the depth of thought to the difficulty of the task. # Constraints - Use clear markdown sections and headings. Favor well-structured, thorough output over terse output. - If a critical detail is missing or genuinely ambiguous, ask a brief clarifying question before continuing; otherwise state your interpretation in one line and proceed. - Do not open with "I'd be happy to help" or any variant. Just start. - Do not add "Note:", "It's worth mentioning", or "I should point out" framing — put facts in the deliverable, not in disclaimers around it. - Treat clearly benign tasks as safe and complete them directly. - Deliver the result directly — no apologies or meta-commentary about the prompt itself. # Output format Return the code in a single fenced code block. Brief inline comments only for non-obvious decisions.
Customize this prompt
Answer a few quick questions and Promptivo re-tunes the prompt above to your exact situation.
Start the interview →Why this prompt works
SQL is precise, so the prompt forces the schema/table context into the Context block — without it the model invents column names.
Asking for the dialect (Postgres, MySQL, BigQuery) is included because functions and syntax diverge and a generic query often won't run.
Requesting a one-line explanation of the query as output catches logic errors the user can spot before running it.
Using this prompt in Claude
For a SQL query, Claude is a strong choice — it's especially good at careful step-by-step reasoning and cleanly structured long-form writing. Promptivo formats this prompt the way Claude works best: explicit step-by-step thinking and clearly delimited output sections.
Paste it into claude.ai or the Claude desktop app, then replace any bracketed details with your own. Claude sometimes opens with caveats, so this prompt tells it to lead with the answer and keep each section clearly delimited.
Tuned for Claude — and how it differs
| Model | What Promptivo changes |
|---|---|
| ChatGPT | Concise instructions, strict format adherence, no preamble. |
| Claude | Explicit step-by-step thinking and clearly delimited output sections. |
| Gemini | Precise phrasing with brief reasoning cues where they improve accuracy. |
| Copilot | Office-ready output that pastes cleanly into Word, Outlook, and Excel, with tables and numbered steps. |
Questions, answered
- What should a SQL prompt always include?
- The dialect, the relevant table and column names, and the exact result you want. Promptivo's interview captures these so the query runs the first time.
- Is Claude good for a SQL query?
- Yes. Claude handles a SQL query well thanks to its careful step-by-step reasoning and cleanly structured long-form writing, and Promptivo tunes the prompt to match — explicit step-by-step thinking and clearly delimited output sections. Paste it into claude.ai or the Claude desktop app.