Write SQL queries from plain English

Describe the data you need in plain words and get a correct, commented SQL query for your database schema, plus a quick way to check it.

Published
Works with
ChatGPT, Claude and Gemini
Level
Intermediate
By
GoodAIPromt editorial team

Writing SQL is easy to get almost right: a wrong join or a missing filter can quietly double your numbers. Giving the AI your actual table structure and asking it to state its assumptions avoids most of these mistakes. This prompt also asks for checks you can run to trust the result.

The prompt

You are a careful data analyst. Write a SQL query.

Database: 
Tables and columns (paste the schema or describe each table):

What I need, in plain English: 
Notes on the data (optional): 

Respond with:
1. Assumptions: how you interpret the question, joins and filters. Ask me if anything is ambiguous.
2. The query, formatted, with a comment on each main step.
3. Possible pitfalls: duplicates from joins, NULLs, time zones, refunds.
4. 2 quick sanity-check queries (e.g. total count or sum to compare with).

Only use the tables and columns I listed. Do not invent column names.

0 of 4 blanks filled

How to use it

  1. Paste the real schema (for example from \d table or the information schema) for accurate column names.
  2. Run the sanity checks and compare them with a number you already know.
  3. Ask for changes in plain English, like "now split it by product category".

Tips

  • Never paste real customer data or passwords; the schema alone is enough.
  • Ask the AI to explain a query you inherited, line by line, before you change it.

Frequently asked questions

What does this prompt do?

Describe the data you need in plain words and get a correct, commented SQL query for your database schema, plus a quick way to check it.

Which AI tools does it work with?

It is written for ChatGPT, Claude and Gemini. It also works in other AI tools that accept text prompts, with small changes.

What do I need to fill in?

4 blanks: postgresql, mysql, bigquery, snowflake, sql server, sqlite; schema; question, e.g. "monthly revenue by country for 2026, only paid orders"; e.g. "orders can be refunded", "times are in utc". Click each blue blank on the page, type your details and press Copy prompt.

Is this prompt free to use?

Yes. You can copy and use it for personal and commercial work.

sqldata analysisqueries

More prompts for ChatGPT, Claude, Gemini.