SQL Query From Plain English
Writes SQL from a natural-language question. Explains the query, flags assumptions about the schema, and warns about performance risks.
The prompt
I'll describe what I want to query. Write the SQL, then explain it. First, ask me these (unless already given): - Which SQL dialect? (Postgres, MySQL, SQLite, BigQuery, Snowflake, other) - The relevant table schemas (columns and types), even if partial. Then output: **The query** — formatted, readable, with meaningful CTEs if it helps clarity over inline subqueries. **What it does** — 2-3 lines explaining the logic in plain English. **Assumptions I made** — anything about the schema, data cleanliness, or intent that I inferred rather than knew. **Performance notes** — if this could be slow (full table scan, missing index, cross join, window over large partition), say so and suggest what to add. Rules: - Never invent columns. If the schema doesn't have what's needed, ask. - Prefer explicit JOINs over old-style comma joins. - Add `LIMIT` to exploration queries. Never to aggregations. - Use lowercase keywords or match the user's style if they gave an existing query. ## How to use it Paste this prompt with your question and (ideally) the relevant schema. Example: "Count active users per day for the last 30 days. Schema: users(id, created_at, last_login_at, plan_tier)." ## Why it works The assumptions section catches the moments where the AI guesses at schema or intent. The performance notes prevent shipping a query that works on 1,000 rows but times out on 10 million.
How to use it
I’ll describe what I want to query. Write the SQL, then explain it.
First, ask me these (unless already given):
- Which SQL dialect? (Postgres, MySQL, SQLite, BigQuery, Snowflake, other)
- The relevant table schemas (columns and types), even if partial.
Then output:
The query — formatted, readable, with meaningful CTEs if it helps clarity over inline subqueries.
What it does — 2-3 lines explaining the logic in plain English.
Assumptions I made — anything about the schema, data cleanliness, or intent that I inferred rather than knew.
Performance notes — if this could be slow (full table scan, missing index, cross join, window over large partition), say so and suggest what to add.
Rules:
- Never invent columns. If the schema doesn’t have what’s needed, ask.
- Prefer explicit JOINs over old-style comma joins.
- Add
LIMITto exploration queries. Never to aggregations. - Use lowercase keywords or match the user’s style if they gave an existing query.
How to use it
Paste this prompt with your question and (ideally) the relevant schema. Example: “Count active users per day for the last 30 days. Schema: users(id, created_at, last_login_at, plan_tier).”
Why it works
The assumptions section catches the moments where the AI guesses at schema or intent. The performance notes prevent shipping a query that works on 1,000 rows but times out on 10 million.
✦ More like this
Related prompts
Book Recommender (Honest)
Recommends 3-5 books based on what you actually liked before. No 'Sapiens for the 400th time.' Includes honest reasons and what NOT to expect.
Chart Type Chooser
Given the data you have and the question you're answering, picks the right chart type and explains what to avoid. No dual-axis, no pie chart traps.
Code Refactor Helper
Refactors a function or file without changing behavior. Explains what changed and why, and flags any behavior it wasn't sure about.