Write SQL From a Plain-English Question

20 Views
0 Uses

Prompt

ChatGPT
Claude
Grok
OpenRouter
Act as a senior data engineer who writes correct, readable SQL. Write a query that answers my question against this schema.

SQL dialect and version (PostgreSQL 16, MySQL 8, SQLite, SQL Server, BigQuery, Snowflake…): {{DIALECT}}
Schema (CREATE TABLE statements or a column list with types and keys): {{SCHEMA}}
The question in plain English: {{QUESTION}}
Notes on the data (soft deletes, time zones, test accounts to exclude, known duplicates): {{DATA_NOTES}}

Do this:
1. Restate the question precisely, resolving ambiguity: what counts as a customer, an order or "active"? Which date range, and in which time zone? State each assumption.
2. Write the query using CTEs with meaningful names, explicit JOIN types, and comments on non-obvious lines. Use only tables and columns from the schema.
3. Explain how it handles NULLs, duplicates from joins, ties, and empty groups.
4. Give two sanity-check queries I can run to verify the result (for example, totals that should reconcile, or a count of rows excluded by each filter).
5. Note indexes that would help if this runs often.

If the schema can't answer the question, say exactly which column or table is missing rather than inventing one.

Customize this prompt

Fill in the variables below to personalize this prompt:

ChatGPT
Claude
Grok
OpenRouter

Model Settings

Recommended Models

ChatGPT Claude Gemini

Temperature

0.7

Max Tokens

2000

Additional Notes

Best for: Getting a correct query for a reporting or product question

About this prompt

“Write SQL From a Plain-English Question” is a free prompt for ChatGPT in the Coding & Software category, 192 words long, added to The Prompt Index on October 28, 2026 by The Prompt Index. Copy it with the button above, paste it into ChatGPT or any other AI chat assistant, and send it.

It has 4 placeholders to fill in first: {{DIALECT}}, {{SCHEMA}}, {{QUESTION}}, {{DATA_NOTES}}. Use the “Customize this prompt” fields to personalise it before you copy.

Recommended models: ChatGPT, Claude, Gemini.

0 upvotes, sent to an AI tool 0 times, viewed 20 times.

Browse all Coding & Software prompts, the AI prompt database or use the AI prompt finder to search every prompt.