AgentDock
1.7k

SQL Query Explainer

Explain a SQL query either clause by clause as written or traced in the actual processing order, from FROM and JOIN through WHERE and SELECT.

Used 53 times

Prompt Template

You are a database instructor whose students keep writing correct SQL by copying patterns from examples, without understanding that the order a query is written in and the order a database engine actually processes it are two completely different sequences, and that mismatch is the root of most SQL confusion.

Work in [MODE:select:explain the query clause by clause as written,trace the actual processing order] mode.

My query is:

[CODE]

If I left [CODE] blank, ask me to paste it before doing anything else instead of inventing a query to explain. My SQL dialect is [DIALECT:select:not sure or generic SQL,MySQL,PostgreSQL,SQLite]. Only mention dialect-specific behavior, such as `LIMIT` syntax differences or string handling, if the query actually touches something that varies by dialect, otherwise treat the explanation as standard SQL.

If I chose clause by clause as written, go through the query top to bottom the way it is typed, `SELECT`, `FROM`, any `JOIN`, `WHERE`, `GROUP BY`, `HAVING`, `ORDER BY`, and `LIMIT` in whatever order they appear, explaining in plain language what each clause specifies. Treat this as describing intent, what the person writing the query is asking for, not as a description of how the database will actually carry it out.

If I chose trace the actual processing order, re-explain the same query but walk through it in the order the database engine really evaluates it, which starts with `FROM` and any `JOIN` clauses building the full working set of rows the query has to consider, then `WHERE` filtering that working set down to matching rows before anything is grouped or selected, then `GROUP BY` bucketing the surviving rows and computing any aggregate functions like `COUNT` or `SUM`, then `HAVING` filtering those groups, then `SELECT` choosing and computing the final output columns, then `DISTINCT` if present, then `ORDER BY` sorting the result, then `LIMIT` cutting it down. At the point where this matters, explain directly why `WHERE` cannot reference a column alias defined in `SELECT`, because `WHERE` runs before `SELECT` ever computes that alias, while `HAVING` can reference it, because `HAVING` runs after. If my query has a `JOIN`, describe concretely what the combined working table looks like immediately after the join runs, before any filtering happens, since that intermediate table is usually the hardest part for a beginner to picture.

Close by asking whether a specific result row in my head does not match what the trace says the query should return, since walking through processing order line by line is usually the fastest way to find exactly where that expectation and the query diverge.

Variables
3

select
text
select

Use this prompt anywhere

10,000+ expert prompts for ChatGPT, Claude, Gemini, and wherever you use AI.

Get Early Access

About SQL Query Explainer

SQL is written in one order and processed in a completely different one. A query reads SELECT first, but the database actually resolves FROM and any JOIN clauses before it ever touches SELECT, and that mismatch explains one of the most common beginner errors, trying to filter on a column alias in WHERE and getting an error, because WHERE runs before SELECT has computed that alias at all.

This tool explains your [CODE] both ways. Clause by clause as written follows the query top to bottom the way it's typed, describing what each part is asking for. Trace the actual processing order rebuilds the explanation in the sequence the engine really uses, FROM and JOIN first to build the working row set, WHERE to filter it, GROUP BY and HAVING to bucket and filter groups, then SELECT, then sorting and limiting. If your query has a join, it describes the intermediate combined table directly, the part most beginners never get to picture because it never appears anywhere in the query's actual output.

Set [DIALECT] to MySQL, PostgreSQL, SQLite, or leave it generic, and dialect quirks only get mentioned when your specific query actually touches one. Run it in the Dock Editor to build a reference of traced queries, pair with the homework helper for a database assignment, or the crud operations explainer once you're ready to see these same operations mapped to app code.

How to Use SQL Query Explainer

1

Paste Your SQL Query

Drop any query into [CODE]. Leaving it blank prompts a request for a real query instead of an invented example.

2

Set Your SQL Dialect

Choose [DIALECT] as MySQL, PostgreSQL, SQLite, or generic SQL if you're not sure. Dialect-specific quirks are only mentioned when your query actually touches one.

3

Choose Written Order or Processing Order

Set [MODE] to clause by clause as written for a straightforward top-to-bottom explanation, or trace the actual processing order to see the sequence the database engine really uses.

4

Watch the Join Build Its Working Table

If your query has a JOIN, the processing-order trace describes the combined table it produces before any filtering happens, the intermediate step that's hardest to picture from the query text alone.

5

Trace a Mismatched Result

If a result you expected doesn't match what the trace explains, that's usually the fastest way to find exactly which clause is behaving differently than you assumed.

Who Uses SQL Query Explainer

Students Learning SQL for the First Time

Paste queries from a database course assignment and use processing-order mode to build a mental model of how the engine actually resolves a query, not just what each clause asks for.

Students Confused Why WHERE Rejects an Alias

You tried to filter on a column alias in WHERE and got an error. The processing-order trace shows directly why WHERE runs before SELECT has computed that alias, and why HAVING would work instead.

Self-Taught Developers Learning Joins

Paste a query with an INNER JOIN or LEFT JOIN and get the intermediate combined table described directly, the row set most tutorials never show you explicitly.

Bootcamp Students Reviewing for a Database Exam

Work through practice queries from a study guide, tracing each one in processing order to build the habit of thinking in execution sequence instead of memorizing clause syntax.

Frequently Asked Questions

You Might Also Like

Discover more prompts that could help with your workflow.

Skip the copy-paste

10,000+ expert-curated prompts for ChatGPT, Claude, Gemini, and wherever you use AI. Our extension helps any prompt deliver better results.

Join the waitlist for exclusive early access to the AgentDock Platform