
- Updated
Write an SQL query from plain English
This prompt acts as a database expert. You name the database, paste your tables and columns and describe what you need, for example the top 10 customers by spend in the last 90 days, and get a query back.
Act as a database expert. Write an SQL query for [DATABASE, e.g. PostgreSQL]. My tables: [PASTE TABLE NAMES AND COLUMNS] What I need: [QUESTION, e.g. the top 10 customers by total spend in the last 90 days, with their order count]. Return the query, explain each part in one line, and mention any index that would make it faster.
Test on a copy of your data first, especially for UPDATE or DELETE queries.
Get a better result
A ready-to-run SQL query for your database, a one-line explanation of each part and a note on any index that would make it faster.
The query uses columns or tables that you do not have.
Fix: Paste the exact table and column names with types, and add “use only these columns and ask me if something is missing”.
- Date or string functions are from the wrong database. Name the database and its version. Date arithmetic and string functions differ between PostgreSQL, MySQL and SQL Server.
- A join multiplies rows, so totals are inflated. Ask “say whether any join can duplicate rows and give me a check query that compares the total with and without the join”.
Paste your own query and ask “explain this query line by line and find any bug, any missing filter and any slow part”. Reviewing is often more useful than writing from scratch.
Use only the columns I pasted, write it for PostgreSQL 15 and tell me whether any join could duplicate rows, with a query to check the totals.
Guides that use this prompt
More chat & writing prompts
See all 465 →More like this
- Design a database schemaChatGPT · Gemini · Claude
- Review a database schema before it goes liveClaude · ChatGPT · Gemini
- Understand a contract in plain EnglishChatGPT · Gemini · Claude
- Polish English emails for workChatGPT · Gemini · Claude
- Find dead code and safe things to deleteClaude · ChatGPT · Claude Code



