⚙️ Settings
WITH recent_orders AS (
SELECT
customer_id,
order_id,
order_date,
total_amount
FROM orders
WHERE order_date >= DATEADD(day, -30, GETDATE())
)
SELECT
customer_id,
COUNT(order_id) AS order_count,
SUM(total_amount) AS total_spent
FROM recent_orders
GROUP BY customer_id
ORDER BY total_spent DESC;
WITH RECURSIVE employee_hierarchy AS (
-- Anchor: top-level rows (no manager)
SELECT
employee_id,
manager_id,
employee_name,
1 AS level
FROM employees
WHERE manager_id IS NULL
UNION ALL
-- Recursive: join children to their parent's result
SELECT
e.employee_id,
e.manager_id,
e.employee_name,
eh.level + 1
FROM employees e
INNER JOIN employee_hierarchy eh
ON e.manager_id = eh.employee_id
)
SELECT *
FROM employee_hierarchy
ORDER BY level, employee_name;
-- Note: SQL Server / Oracle: drop the RECURSIVE keyword (just WITH employee_hierarchy AS (...))
SELECT
o.order_id,
c.customer_name,
o.order_date,
p.product_name,
oi.quantity
FROM orders o
INNER JOIN customers c
ON o.customer_id = c.customer_id
LEFT JOIN order_items oi
ON o.order_id = oi.order_id
LEFT JOIN products p
ON oi.product_id = p.product_id
WHERE o.order_date >= '2026-01-01'
ORDER BY o.order_date DESC;
SELECT
DATE_TRUNC('month', order_date) AS order_month, -- PostgreSQL
-- FORMAT(order_date, 'yyyy-MM') AS order_month, -- SQL Server
-- DATE_FORMAT(order_date, '%Y-%m') AS order_month, -- MySQL
COUNT(*) AS order_count,
SUM(total_amount) AS revenue
FROM orders
GROUP BY DATE_TRUNC('month', order_date)
ORDER BY order_month;
SELECT
customer_id,
order_id,
order_date,
total_amount,
ROW_NUMBER() OVER (
PARTITION BY customer_id
ORDER BY order_date DESC
) AS order_rank,
SUM(total_amount) OVER (
PARTITION BY customer_id
ORDER BY order_date
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS running_total
FROM orders;
CREATE PROCEDURE GetCustomerOrders
@CustomerId INT,
@StartDate DATE = NULL,
@EndDate DATE = NULL
AS
BEGIN
SET NOCOUNT ON;
SELECT
order_id,
order_date,
total_amount
FROM orders
WHERE customer_id = @CustomerId
AND (@StartDate IS NULL OR order_date >= @StartDate)
AND (@EndDate IS NULL OR order_date <= @EndDate)
ORDER BY order_date DESC;
END;
-- Call it: EXEC GetCustomerOrders @CustomerId = 101, @StartDate = '2026-01-01';
MERGE INTO customers AS target
USING staging_customers AS source
ON target.customer_id = source.customer_id
WHEN MATCHED THEN
UPDATE SET
target.customer_name = source.customer_name,
target.email = source.email,
target.updated_at = GETDATE()
WHEN NOT MATCHED THEN
INSERT (customer_id, customer_name, email, created_at)
VALUES (source.customer_id, source.customer_name, source.email, GETDATE());
#FACC15
rgb(250, 204, 21)
rgb(98%, 80%, 8%)
hsl(46, 96%, 53%)
hsv(46, 92%, 98%)
cmyk(0%, 18%, 92%, 2%)
SQL Query Explainer — Get a Plain-English Breakdown of a SQL Query
The SQL Query Explainer reads any SQL query and produces a plain-English breakdown of what it selects, joins, filters, and sorts. It's built for developers, analysts, and anyone learning SQL who needs to understand what a SQL query does quickly — reviewing someone else's query, documenting a report, or checking your own logic before running it. It works entirely through pattern matching, running offline with no AI involved.
⚡ Key Takeaways
- Breaks down what a query selects, joins, filters, groups, and sorts — in plain English.
- Runs entirely offline through pattern matching — no AI, nothing sent anywhere.
- Flags UPDATE and DELETE statements missing a WHERE clause before you run them.
- Explains query logic, not performance — use your database's execution plan for that.
What, Who, When & Why
| What it's for | Reads a SQL query and produces a plain-English breakdown of what it selects, joins, filters, and sorts. |
|---|---|
| Who it's for | Developers, analysts, and SQL learners reviewing unfamiliar or complex queries. |
| When to use it | When reviewing someone else's query, documenting a report, or double-checking your own logic before running it. |
| Why it's needed | Parsing a complex, unfamiliar query by eye is slow and easy to misread, especially with multiple joins or nested conditions. |
| Best way to use it | Pay close attention to its warning about UPDATE or DELETE statements missing a WHERE clause before running anything against real data. |
How to Use the SQL Query Explainer
- Paste any SQL query — SELECT, INSERT, UPDATE, DELETE, CREATE, or a CTE (WITH) statement.
- Click Explain.
- Read the structured breakdown covering the statement type, tables, joins, filters, grouping, and sorting.
Example
Given this query:
SELECT c.name, COUNT(o.id) FROM customers c LEFT JOIN orders o ON o.customer_id = c.id GROUP BY c.name;
The explainer produces a breakdown similar to:
📋 Statement type: SELECT 📌 Selects: c.name, COUNT(o.id) 🗄️ Main table: customers 🔗 LEFT JOIN orders — matched on: o.customer_id = c.id 📊 Groups results by: c.name
For a query with a WHERE clause and an ORDER BY, the breakdown would additionally list the filter condition and sort order as their own separate lines — giving you a clear, structured checklist of everything the query does instead of having to parse the raw SQL syntax yourself.
Key Features
- Identifies the statement type (SELECT, INSERT, UPDATE, DELETE, CREATE, or CTE).
- Breaks down selected columns, aggregate functions used, and the main table.
- Explains joins, including join type and the matching condition.
- Summarizes WHERE filters, GROUP BY, HAVING, ORDER BY, and LIMIT clauses.
- Flags UPDATE and DELETE statements that lack a WHERE clause, since those affect every row in the table.
- Runs entirely offline using pattern matching — no query is sent anywhere, and no AI is involved.
Practical Use Cases
- Reviewing unfamiliar queries: quickly understand what a colleague's or a legacy query actually does before modifying it.
- Learning SQL: see a structured breakdown of a query's logic while studying how each clause works.
- Pre-execution safety check: catch UPDATE or DELETE statements missing a WHERE clause before running them against a real database.
- Documentation: generate a quick plain-English summary of a query for a wiki or code comment.
- Code review: get a fast structural overview of a query before diving into a detailed review.
Tips for Best Results
- Run your query through the SQL Formatter first if it's dense and unindented — a cleanly formatted query is easier to visually cross-reference against the explanation.
- Pay special attention to the safety warning about missing WHERE clauses before running any UPDATE or DELETE statement against production data.
- Use the explanation as a starting point for documentation, then add any business-specific context the tool wouldn't know, like why a particular filter exists.
Related Terminology
This tool uses pattern matching — recognizing structural keywords like SELECT, FROM, and JOIN — rather than a full SQL parser or AI model, meaning it works entirely offline and doesn't send your query anywhere for analysis. This is different from a database's own "query execution plan," which explains how the database will physically execute a query rather than what it logically does.
Important Considerations
Because it relies on recognizable SQL keywords and structure, extremely unusual formatting, vendor-specific syntax, or deeply nested subqueries may not be broken down perfectly — treat the explanation as a helpful summary rather than an exhaustive, guaranteed-complete analysis of complex queries. This tool explains what a query is asking for, not how efficiently the database will run it — for performance analysis, you'd need your database's own execution plan tools.
Related Tools
Format a messy query first with the SQL Formatter for easier reading. To remove comments before explaining or sharing a query, use the Query Sanitizer. For boilerplate patterns to compare against, browse the SQL Query Templates.
Frequently Asked Questions
Does this use AI to explain my query?
No, it uses offline pattern matching against known SQL keywords and structure — your query is never sent anywhere, and no AI model is involved.
Can it explain INSERT, UPDATE, and DELETE statements, not just SELECT?
Yes, it recognizes and explains SELECT, INSERT, UPDATE, DELETE, CREATE, and WITH (CTE) statements.
Will it warn me about a dangerous query?
Yes, it flags UPDATE and DELETE statements that don't include a WHERE clause, since those would affect every row in the table.
Does it tell me how fast or efficient my query is?
No, it explains what the query logically does, not its performance — for execution speed and efficiency, use your database engine's own query execution plan tools.
Tools for analysts, developers & QA engineers
33 free, browser-based utilities — text and list tools, SQL helpers, converters, and small productivity apps. Everything runs locally; nothing you type or paste is ever uploaded.
For Analysts
Clean lists, build SQL fragments, and reshape data without opening a spreadsheet.
For Developers
Format SQL, convert data formats, and handle everyday text and encoding tasks.
For QA Engineers
Generate test data, compare text output, and sanitize queries before sharing them.