Coding · Free prompt

AI prompt for writing SQL

Describing what you want in plain English is easy; getting the joins and grouping right is not. This prompt turns a plain description into a correct, readable SQL query, and explains it so you can trust and adapt it.

Copy this prompt

You are an expert SQL developer who writes clear, correct queries.

Write a SQL query for the request below.

DATABASE: [e.g. PostgreSQL, MySQL, SQLite, BigQuery]

TABLES AND COLUMNS:
[LIST EACH TABLE AND ITS RELEVANT COLUMNS, e.g. orders(id, user_id, total, created_at)]

WHAT I NEED:
[DESCRIBE THE RESULT IN PLAIN ENGLISH, e.g. "total revenue per customer for the last 30 days, highest first"]

Rules:
- Use the exact table and column names I gave you.
- Write it for the specific database I named.
- Format it to be readable, with the query on multiple lines.
- Do not invent columns. If something is missing, ask me instead of guessing.

Return the query, then explain in 2-3 lines what it does and any assumptions you made.

Paste it into ChatGPT, Claude, or Gemini and replace the text in [SQUARE BRACKETS] with your own details.

Why this prompt works

  • 01

    Giving it your real schema is what makes the difference between a query that runs and one that guesses column names.

  • 02

    Naming the database matters: date functions and syntax differ between Postgres, MySQL, and BigQuery.

  • 03

    Telling it to ask rather than guess prevents silent, invented columns that fail when you run them.

How to adapt it

  • -Paste your actual CREATE TABLE statements if you have them. That removes all ambiguity.
  • -Always run the query on a small sample first. Verify the numbers before trusting them.
  • -If it is slow, follow up with: "How would you make this query faster?"

Frequently asked questions

Why does this write a sql query prompt work better than a basic one?

Giving it your real schema is what makes the difference between a query that runs and one that guesses column names.

How do I adapt this prompt for my own situation?

Paste your actual CREATE TABLE statements if you have them. That removes all ambiguity.

Is this prompt free, and does it work with Claude and Gemini as well as ChatGPT?

Yes on both. The prompt is completely free to copy, and it is model-agnostic - it produces strong results in ChatGPT, Claude, and Gemini. Paste it into any of them.

Want this tuned to your exact situation?

A template gets you started. Deepclario takes your version of a prompt, scores it, asks what is missing, and rewrites it for your specific task. Free, no account needed.

Improve my prompt free

Or browse the full prompt library.