Promptivo logoPromptivo

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.

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
Work the problem internally, then give only the result. Do not narrate your reasoning unless it is part of the deliverable.

# Constraints
- Follow the requested format exactly. Default to clean markdown. Be concise — no filler, no restating the question.
- Deliver the single best answer rather than hedging across several.
- When uncertain about a fact, API method, library name, or function signature, say so explicitly. Do not produce a plausible guess.
- Do not invent citations, URLs, or package names. If you don't know one, omit it or flag that you don't.
- Do not include 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.

Tuned for your model

Get a version optimized for the AI you actually use:

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.

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.

Related prompts