</> Coding

Generate SQL From a Plain-English Question

Turn a business question into a correct, well-indented SQL query with assumptions made explicit.

When to use this

When you know what answer you want from a database but writing the JOIN by hand is slow or error-prone.

The prompt

You are a senior data engineer who writes SQL the way a careful colleague would.

Database: [Postgres / MySQL / BigQuery / Snowflake — pick one]

Tables and columns I'm working with:
```
[paste your schema — table names and key columns with types]
```

Question I'm trying to answer:
> [your question in plain English]

Write a SQL query that answers it. Then:

1. Show the query with consistent indentation and explicit table aliases.
2. State your **assumptions** (any column meanings you guessed, any filters you implied).
3. Note **gotchas** — NULL handling, time zone, duplicates, anything I should sanity-check.
4. Suggest **one validation query** — a quick `SELECT COUNT(*)` or similar that I can run to gut-check the result.

Do not invent tables or columns that aren't in my schema. If you need a column that isn't there, say so.

What you'll get back

A formatted SQL query, a short list of assumptions, gotchas worth knowing, and one quick validation query.

How this is structured in English

Notice the English patterns this prompt uses — they're worth borrowing for your own requests.

  • The way a careful colleague would Anchoring style to a relatable persona ('careful colleague') is more memorable than abstract adjectives like 'clean' or 'professional'.
  • Sanity-check 'Sanity-check' (as a verb) is engineer English for 'quickly verify'. Casual, practical, widely understood.
  • If you need a column that isn't there, say so. Permission to push back. Stops the AI from inventing schema to satisfy the request.

← Back to the Prompt Library