Example result: Write an SQL query from plain English
AI-generated example · SQL Helper
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.

text-sql-from-english — claude — 59 words

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

What you will get

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.

Common mistake

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”.

Also watch for
  • 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”.
Try a variation: check my query

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.

Still not right? Reply with this

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 →