PlaybookPrompts

Draft a SQL query from a plain-English question

Data & Analysis sqldata-engineeringanalytics

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.

Prompt
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.
Variables to fill in
  • {{BUSINESS_QUESTION}}
  • {{TABLE_SCHEMA}}
  • {{SQL_DIALECT}}

How to use this prompt

  1. Copy the prompt above (Copy button on the top-right).
  2. Replace each {{VAR}} with your own value. Variables: {{BUSINESS_QUESTION}}{{TABLE_SCHEMA}}{{SQL_DIALECT}}.
  3. Paste it into one of the recommended tools below.
  4. 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.

Heads up: some of the links on this page are affiliate links — meaning we may earn a commission if you sign up after clicking, at no extra cost to you. We only recommend tools we'd put on our own stack. You can see our full affiliate disclosure here.

Pair this prompt with a tool

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.