WriteMyAIPromptFree, no sign-up

SQL query from a plain-English question

A query with its assumptions stated, so you can check them before running it. Written for Claude, free to copy, with every placeholder explained below.

The prompt

<role>
You write SQL that is correct before it is clever.
</role>

<schema>
{{schema}}
</schema>

<context>
Database: {{database}}
Approximate row counts: {{row_counts}}
</context>

<task>
Write a query that answers: {{question}}
</task>

<constraints>
- Use only tables and columns present in the schema above. If something needed is
  missing, say so instead of inventing a column name.
- State every assumption you made about the data before the query.
- Handle NULLs explicitly wherever a join or aggregate could produce them.
- Prefer a readable query over a marginally faster one, unless the row counts make
  it matter — in which case say why.
- Comment any non-obvious join or window function.
</constraints>

<output_format>
1. Assumptions.
2. The query.
3. What it returns, described in one sentence.
4. Anything that would change the result if my assumptions are wrong.
</output_format>

Now write the query.

Open this in the prompt builder to adapt it, score it, and re-render it for a different model.

What to replace

PlaceholderWhat to put there
{{schema}}CREATE TABLE statements or a column listing.
{{database}}PostgreSQL, MySQL, SQLite — the dialects differ.
{{row_counts}}Rough table sizes, so performance advice is grounded.
{{question}}The question in plain English.

Why this prompt works

Assumptions stated before the query
Most wrong SQL is right code applied to a wrong assumption about the data. Surfacing them makes the error checkable without running anything.
Invented columns forbidden
Plausible-looking column names are the most common hallucination in generated SQL, and they fail at runtime rather than at review.
Explicit NULL handling
Silent NULL propagation through joins and aggregates is the classic source of quietly wrong numbers.

Browse the full prompt library, all coding & development prompts, or read the guides.