SQL Query Writer with Explanation

Writes correct SQL from a plain-English question and your schema — states its assumptions, explains the query in plain language, and flags the edge cases in your data.

Fill in the blanks

Prompt variables

3 variables detected — fill them and Copy inserts your values (0/3 filled).

Write SQL to answer my question, given my schema. Correctness over cleverness — and surface every assumption instead of silently making it. **Schema (tables, columns, types, relationships):** {{schema}} **Database engine:** {{engine}} **My question in plain English:** {{question}} Deliver: **1. Assumptions check.** Before the SQL: list every interpretation choice my question forces ("active users" = logged in within 30 days? does "revenue" include refunds? should ties both appear?). Pick the most reasonable reading for each, state it, and mark alternatives that would change the query materially. **2. The query.** Idiomatic for {{engine}}, formatted for reading: - CTEs with meaningful names over nested subqueries when logic has stages - Explicit JOIN conditions; comment any join where fanout could silently duplicate rows (the classic sum-inflation bug) - Handle NULLs deliberately where they lurk (LEFT JOIN results, aggregates, NOT IN traps — use NOT EXISTS) - Comment each non-obvious line with WHY, not what **3. Plain-language walkthrough.** 3–6 sentences: what the query does stage by stage, readable by a non-SQL colleague who needs to trust the number. **4. Edge cases in the result.** What could make this query return something misleading given MY schema: empty groups that vanish vs. show as zero, timezone boundaries on date filters, duplicates in the source, division by zero. One line each with the fix if I need it. **5. Sanity check query.** One cheap query I can run to validate the main result (row counts to reconcile, a known subtotal to compare).
Field notes

Comments (0)

LLM Atlas

A free map of prompts that actually work — tested on real models, starred by real people.

© 2026 LLM AtlasPrompts default to CC0 unless stated.