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.
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.
Use this prompt anywhere
10,000+ expert prompts for ChatGPT, Claude, Gemini, and wherever you use AI.
Get Early AccessSQL 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.
Drop any query into [CODE]. Leaving it blank prompts a request for a real query instead of an invented example.
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.
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.
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.
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.
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.
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.
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.
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.
The clause order in a query reflects how a person naturally describes a request, starting with what to select. But the database has to know which rows it's working with before it can filter, group, or select from them, so it processes FROM and JOIN first, then WHERE, then GROUP BY and HAVING, then SELECT, then sorting and limiting.
WHERE runs before SELECT in actual processing order, so the alias SELECT would define doesn't exist yet when WHERE evaluates. HAVING runs after SELECT's aggregate calculations, which is why HAVING can reference an alias that WHERE cannot, even though both clauses look similar on the page.
WHERE filters individual rows before any grouping happens. HAVING filters groups after GROUP BY has bucketed rows and computed aggregate functions like COUNT or SUM. A condition on a raw column belongs in WHERE, a condition on an aggregate result belongs in HAVING.
A JOIN builds a combined working table by matching rows between two or more tables based on the join condition, before WHERE, GROUP BY, or SELECT touch anything. This tool's processing-order trace describes that intermediate table directly for your specific query, which is usually the hardest part to picture from the query text alone.
The core processing order, FROM and JOIN, then WHERE, then GROUP BY and HAVING, then SELECT, then ORDER BY and LIMIT, is standard across MySQL, PostgreSQL, and SQLite. Set [DIALECT] to your specific database and any syntax quirks that actually apply to your query get mentioned.
Written-order mode is a faster read for understanding what a query is asking for at a glance. Processing-order mode is the one to use when a query isn't returning what you expect, since it matches how the database actually evaluates the query and surfaces exactly where your assumption and its behavior diverge.
Discover more prompts that could help with your workflow.
Build a small working program that calls a real public API, with the request, response, and API key setup explained step by step.
Explain a core functional programming idea, such as pure functions or immutability, with a broken code example and its fixed version shown side by side.
Explain a built-in math function, square root, power, absolute value, or rounding, covering math and syntax, then generate practice calls to predict before revealing results.
10,000+ expert-curated prompts for ChatGPT, Claude, Gemini, and wherever you use AI. Our extension helps any prompt deliver better results.