How to Understand and Explain a Complex SQL Query
Use the SQL Query Explainer to break down complex SQL queries — joins, CTEs, window functions, subqueries — into plain-English explanations.
Tool Used
SQL Query Explainer
Paste your SQL query
Open the SQL Query Explainer tool. Paste the SQL query you want to understand into the input field. The tool accepts standard SQL including SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, CTEs (WITH clauses), subqueries, and window functions. Both PostgreSQL and MySQL dialect features are supported.
Click Explain to see the breakdown
Click Explain. The tool analyzes the query structure and generates a plain-English explanation of each clause. The explanation is organized in the logical execution order: FROM and JOINs first, then WHERE filtering, then GROUP BY and HAVING, then SELECT computation, then ORDER BY and LIMIT.
Understand the JOIN logic
For queries with JOINs, the explanation identifies each join type (INNER, LEFT, RIGHT, FULL OUTER) and describes what it means: INNER JOIN returns only rows with a match in both tables; LEFT JOIN returns all rows from the left table with NULLs for non-matching right rows. The explanation also identifies the join condition and what relationship it represents.
Read CTE and subquery explanations
For queries using CTEs (WITH clauses), each CTE is explained separately before the main query. The explanation describes what data the CTE selects and how the main query uses it. For subqueries, the explanation identifies whether the subquery is correlated (references the outer query) or non-correlated (runs once independently), and describes the subquery's purpose.
Check performance notes
The explainer highlights potential performance concerns: SELECT * (selects all columns, preventing index-only scans), correlated subqueries (re-run for every row of the outer query — consider converting to a JOIN), GROUP BY on high-cardinality columns, and missing ORDER BY for windowed aggregations. Use these notes as starting points for query optimization before running EXPLAIN ANALYZE in your database.
All done!
You are ready to use SQL Query Explainer like a pro.