Prompt library
Explain what a SQL query really does
Execution-order walkthroughs match how SQL actually behaves rather than how it reads, which is where most misreadings start. The silent-behaviors section names the three mechanisms (join fan-out, NULL logic, quiet row loss) behind nearly every dashboard number that turned out wrong.
Last reviewed July 17, 2026
The prompt
Explain the SQL query below.
{{query}}
Produce:
1. Plain-language answer first: what question does this query answer, in one sentence a stakeholder would accept.
2. The walk-through: step through the query in execution order (FROM/JOIN, WHERE, GROUP BY, HAVING, SELECT, ORDER/LIMIT), one plain sentence per step, naming what rows exist after each.
3. The grain: one row of output represents what, exactly.
4. The silent behaviors: where rows quietly disappear (inner joins on nullable keys, WHERE on a NULL column), where duplicates could inflate numbers (fan-out joins before an aggregate), and how NULLs, ties, and timezones are treated.
5. The mismatch check: 3 plausible intents someone might have had, and whether this query serves each. Wrong-question bugs outnumber wrong-syntax bugs.
6. Suggested comment block: the header comment this query should carry so nobody has to do this again.
If the query references objects whose definition you cannot see, list the assumptions you are making about them.Run in idaptOpens a new chat with the prompt prefilled. Nothing sends until you press send.
Fill in the variables
| Variable | What it is | Example |
|---|---|---|
| {{query}} | The query to explain | [paste the SQL] |