SQL Boy
TutorialsPlayground

Format & Validate

SQL FormatterSQL MinifierSyntax Validator

Convert

JSON to SQLCSV to SQLSQL to JSONRegex to SQLExcel to SQLSQL Dialect Convertersoon

Visualize

ER Diagram GeneratorSQL Schema Diff

Generate

SQL Mock Data Generator

Analyze

SQL Query ExplainerSQL Query Analyzer

Workflow hubs

FormattingConversionSchemaAnalysis
View all tools
Daily ChallengeInterviewsCheat SheetBlog

© 2026 SQL Boy. Built for developers.

ContactPrivacyTermsAI Usage PolicyEditorial StandardsAboutRSS Feed

New conversation

What can I help with?

Ask about this page, get a hint on a challenge, or explore SQL concepts.

I know what's on this page and can give answers grounded in SQL Boy content.

Current page

Query Explainer

/tools/query-explainer

Usage status will load after login
SQL Boy
TutorialsPlayground

Format & Validate

SQL FormatterSQL MinifierSyntax Validator

Convert

JSON to SQLCSV to SQLSQL to JSONRegex to SQLExcel to SQLSQL Dialect Convertersoon

Visualize

ER Diagram GeneratorSQL Schema Diff

Generate

SQL Mock Data Generator

Analyze

SQL Query ExplainerSQL Query Analyzer

Workflow hubs

FormattingConversionSchemaAnalysis
View all tools
Daily ChallengeInterviewsCheat SheetBlog

SQL Query Explainer

Paste any SQL query and get a plain-English, clause-by-clause breakdown. Click any card to highlight the corresponding SQL in the editor.

SELECT · FROM · JOINWHERE · GROUP BY · HAVINGORDER BY · LIMIT · WITH (CTE)
Click a card to highlight that clause
SQL inputSELECT

How to Read a SQL SELECT Statement

A SQL SELECT query is built from a collection of clauses, each performing a distinct operation on the data. They execute in a specific logical order that is different from the order in which you write them.

Logical execution order

  1. FROM / JOIN — Identify and combine the source tables.
  2. WHERE — Filter individual rows from the combined source.
  3. GROUP BY — Collapse the remaining rows into groups.
  4. HAVING — Filter groups using aggregate conditions.
  5. SELECT — Compute the output columns (and aliases).
  6. DISTINCT — Remove duplicate rows, if requested.
  7. ORDER BY — Sort the final result set.
  8. LIMIT / OFFSET — Trim the result to a specific page.

This order matters when writing queries: you cannot reference a SELECT-level alias in a WHERE clause (because WHERE runs before SELECT), but you can reference it in an ORDER BY clause (because ORDER BY runs after SELECT).

Clause quick reference

ClausePurposeRequired
SELECTSpecify which columns (or expressions) to returnYes
FROMSpecify the source table(s)Usually
JOINCombine rows from a second table based on a conditionNo
WHEREFilter rows before aggregationNo
GROUP BYAggregate rows that share a common valueNo
HAVINGFilter aggregated groupsNo
ORDER BYSort the result setNo
LIMITRestrict number of rows returnedNo
WITHDefine named subqueries (CTEs) for reuseNo

JOIN types explained

TypeReturns
INNER JOINRows that match in both tables
LEFT JOINAll rows from the left table; NULLs for non-matching right rows
RIGHT JOINAll rows from the right table; NULLs for non-matching left rows
FULL JOINAll rows from both tables; NULLs where no match exists
CROSS JOINEvery combination of rows from both tables (Cartesian product)

WHERE vs HAVING

A common source of confusion is knowing when to use WHERE versus HAVING:

  • Use WHERE to filter rows before grouping — e.g., WHERE country = 'USA'.
  • Use HAVING to filter groups after aggregation — e.g., HAVING COUNT(*) > 5.

You can combine both in the same query:

SELECT country, COUNT(*) AS users
FROM   users
WHERE  is_active = 1        -- filters rows first
GROUP  BY country
HAVING COUNT(*) > 100       -- then filters groups

How to use the explainer for learning

The biggest value of this tool is not just translating SQL into English. It is helping you build a mental model for what each clause contributes to the final result.

Debug a query you already wrote

Paste a real query, click through each clause, then compare the explanation order to the logical execution order.

Learn new SQL patterns

Load a sample, inspect the clause cards, then rewrite the query manually in the playground from memory.

Review generated SQL before it ships

Useful when a query comes from an ORM, query builder, or dynamic filter layer and you want to inspect the final structure before checking performance or safety.

Choose the concept guide that matches the clause you are stuck on

Plain-English clause cards are a starting point. These paths connect the explanation back to the specific article cluster behind that clause pattern.

The query is hard because it uses named stages or recursion

Use these guides when the explainer shows a WITH clause and you need a stronger mental model for multi-step SQL.

Mastering CTEsMastering Recursive CTEs

The confusing part is joins, grouping, or post-aggregation filters

This path fits when the clause cards are readable but the result grain or join logic still feels easy to misread.

Mastering SQL JoinsSQL HAVING Clause Explained

The explained query came from code, not from a human

Relevant when you are reading generated SQL and need the security and maintainability context behind the final text.

Dynamic SQL Best PracticesPreventing SQL Injection

Go deeper on the clauses you see most

If the explainer helps you read the query but the concept still feels fuzzy, jump into one of these focused guides.

Understanding Window Functions

Useful when the explainer shows OVER, PARTITION BY, or ranking logic that feels opaque.

Mastering CTEs

Helpful when your query starts with WITH and breaks into multiple named steps.

Mastering SQL Joins

A strong follow-up when the FROM and JOIN section is still hard to reason about.

Dynamic SQL Best Practices

Useful when the explained query is assembled at runtime and you need to reason about the final SQL shape safely.

Preventing SQL Injection

Relevant when query explanation is also part of a security review for user-controlled filters or sorting.

Frequently Asked Questions

Related tools

Query Analysis WorkflowSQL Query AnalyzerSQL FormatterSyntax ValidatorSQL Playground

© 2026 SQL Boy. Built for developers.

ContactPrivacyTermsAI Usage PolicyEditorial StandardsAboutRSS Feed