Draft a SQL query from a plain-English question
Translating a business question into SQL is where most non-engineers get stuck. This prompt turns a natural-language ask into a ready-to-run query with inline comments explaining each clause.
You are a senior data analyst. I need you to write a SQL query that answers the following business question.
Business question: {{BUSINESS_QUESTION}}
Database context:
- Table names and key columns: {{TABLE_SCHEMA}}
- Database dialect (e.g., BigQuery, PostgreSQL, Snowflake, MySQL): {{SQL_DIALECT}}
Follow these steps:
1. Restate the business question in one sentence to confirm you understand it.
2. Identify which tables and joins are needed and briefly explain why.
3. Write the full SQL query. Use CTEs instead of nested subqueries where it improves readability.
4. Add an inline comment above each major clause (WITH, SELECT, FROM/JOIN, WHERE, GROUP BY, ORDER BY) explaining what it does in plain English.
5. Flag any assumptions you made (e.g., assumed a column means X, assumed date field is UTC).
6. List one or two edge cases that could cause the query to return wrong results (e.g., NULLs, duplicates, timezone mismatch) and suggest a guard for each.
Do not fabricate column names. If the schema I provided is ambiguous, ask a clarifying question before writing the query. {{BUSINESS_QUESTION}}{{TABLE_SCHEMA}}{{SQL_DIALECT}}
How to use this prompt
- Copy the prompt above (Copy button on the top-right).
- Replace each
{{VAR}}with your own value. Variables:{{BUSINESS_QUESTION}}{{TABLE_SCHEMA}}{{SQL_DIALECT}}. - Paste it into one of the recommended tools below.
- Iterate: tighten constraints in the prompt if the output is generic.
Why this prompt is structured this way
The prompt is split into explicit steps because LLMs do better when the path is named, not implied. Each variable forces specificity at the input layer — vague inputs get vague outputs.
Pair this prompt with a tool
Perplexity
$0/mo (Pro at $20)AI search engine with citations.
Perplexity is the answer engine Google would build if it weren't protecting search ad revenue. Cited answers, follow-up questions, focused source modes.
Claude (Anthropic)
$0/mo (Pro at $20)Frontier model with long context and strong reasoning.
Claude (Opus / Sonnet / Haiku tiers) is the assistant favored by writers and engineers who care about reasoning quality and tone. 1M token context on Opus.
ChatGPT (OpenAI)
$0/mo (Plus at $20)The category-defining general-purpose AI assistant.
ChatGPT has the broadest feature surface: image gen, voice, custom GPTs, web browsing, code execution. Often the right default; sometimes beaten on specific tasks by Claude or Perplexity.
The PlaybookPrompts weekly
One short email per week. The five sharpest prompts we found, one tool worth your attention, one anti-pattern to avoid. Unsubscribe in one click.
Newsletter signup is not configured. Set PUBLIC_NEWSLETTER_USERNAME in the build env.