The hard part of SQL is rarely the syntax; it is the assumptions hidden in the question. This prompt makes the model state those assumptions, use only your real tables and explain the query back to you, so you can trust the result before you share it.
SQL query from plain English
Turns a plain-English question into a commented, read-only SQL query with its assumptions spelled out; change the dialect, schema and question.
You are a careful data analyst who writes correct, readable SQL. Write a PostgreSQL query that answers this question: Which 10 customers spent the most in the last 90 days, and how many orders did each place? Schema (tables and columns): customers (id integer, name text, country text, created_at timestamp); orders (id integer, customer_id integer, status text, total_amount numeric, created_at timestamp) Notes on the data: only orders with the status paid count, amounts are in GBP and timestamps are stored in UTC. Steps: 1. Restate the question in one sentence and list your assumptions, such as how you handle duplicates, nulls, time zones and cancelled records. 2. Write the query using only the tables and columns in the schema, with clear aliases, CTEs for multi-step logic and a short comment above each step. 3. Explain in plain words what the query does, step by step. 4. Suggest one quick check that the result is right, such as a row count or a sample of rows. Do not invent tables or columns. If the schema lacks something the question needs, say what is missing instead of guessing. Keep the query read-only: no INSERT, UPDATE, DELETE or DROP.
Click a highlighted part to change it.
Make it yours
Pick an option or type your own. The preview updates as you go: copy it when it reads right, or open it straight in your AI tool.
Your version stays in this browser. Ctrl or ⌘ + Enter copies it.
About this prompt
Why it works
- The real schema
Exact table and column names let the model write a query that runs, instead of one built on guessed names.
- Assumptions first
Stating how duplicates, nulls and dates are handled exposes the decisions that quietly change the answer.
- Readable structure
CTEs and step comments make the query easy to check, reuse and hand to a colleague.
- Read-only and honest
Banning invented columns and write statements keeps the query safe to run against real data.
Tips for better results
- Paste table definitions only, never real customer rows. Column names and types are enough.
- Run a new query on a sample first, for example with LIMIT 100, and sanity-check the numbers before you share them.
- Put business rules in the notes, such as what counts as an active customer; the schema cannot tell the model that.
- If a query is slow, follow up with “Explain how to make this faster and which index would help.”
Variations to try
- Monthly trend
Write a PostgreSQL query showing monthly revenue and the number of paid orders for the last 12 months, including months with no orders as zero. Table: orders (id, customer_id, status, total_amount, created_at); only rows with the status paid count. Use generate_series for the months and a LEFT JOIN, comment each step and explain the query in plain words.
- Explain a query I inherited
Explain the SQL query below in plain English for a product manager. Describe what each part does in order, what one row of the result represents, the assumptions it makes about the data and anything that looks like a bug or could give misleading numbers. Do not rewrite it unless I ask.
Questions
Will the query run first time?
It has the best chance when you paste the real schema and choose the right dialect. Always run it on a sample and check the numbers before you rely on them.
Is it safe to paste my database schema?
Table and column names are usually low risk, but check your company’s policy first. Never paste real customer records, passwords or connection strings.
Did this prompt work for you?
Thanks. Your answer helps the next person.
Quick copy
SQL query from plain English
Copies your version from the studio.
For prompt makers
Got a prompt that works every time?
Send it in. We review every submission by hand and credit you on the page when it goes live.