How to Explain a SQL Query in Plain English: Step-by-Step Tutorial
Table of Contents
- Step 1: Open the SQL Query Explainer
- Step 2: Paste Your SQL Query
- Step 3: Click "Explain Query"
- Step 4: Read the Plain English Summary
- Step 5: Review the Structured Breakdown
- Step 6: Check the Complexity Score
- Step 7: Compare Different Queries
- Step 8: Use the Other Modes
- Related Tools & Guides
- Related Articles
Step 1: Open the SQL Query Explainer
Go to the SQL Query Explainer page. The Explain tab is selected by default. You will see a code editor, a dialect selector, and the mode tabs.
Step 2: Paste Your SQL Query
Paste any SQL query into the editor. Here is a sample query to try:
SELECT
c.customer_name,
COUNT(o.order_id) AS total_orders,
SUM(o.amount) AS total_revenue
FROM customers c
INNER JOIN orders o ON c.customer_id = o.customer_id
LEFT JOIN refunds r ON o.order_id = r.order_id
WHERE o.status = 'paid'
AND o.order_date >= '2024-01-01'
AND r.refund_id IS NULL
GROUP BY c.customer_name
HAVING SUM(o.amount) > 1000
ORDER BY total_revenue DESC
LIMIT 10;
Or click "Load Sample" to use a built-in example.
Step 3: Click "Explain Query"
Click the blue "Explain Query" button. The results panel appears below the editor with three sections.
Step 4: Read the Plain English Summary
The first section is a plain English sentence describing what the query does. For the sample query, it explains that the query selects customer names and calculates order counts and revenue totals, joining customers with orders and refunds, filtering for paid orders with no refunds, grouping by customer, and returning the top 10 by revenue.
Step 5: Review the Structured Breakdown
The second section shows cards for each structural element:
- Query Type โ SELECT
- Tables โ customers, orders, refunds
- Columns โ customer_name, COUNT(order_id), SUM(amount)
- Join Conditions โ INNER JOIN orders, LEFT JOIN refunds
- Filters โ status = 'paid' AND order_date >= '2024-01-01' AND refund_id IS NULL
- Grouping โ customer_name
- Aggregations โ COUNT, SUM
- Sorting โ total_revenue DESC
- Limiting โ LIMIT 10
Step 6: Check the Complexity Score
The complexity score appears as a number with a colored bar and label. The sample query scores around 55 (Complex) because it has 2 JOINs (24 points), GROUP BY (8 points), HAVING (5 points), 2 aggregations (6 points), and baseline (10 points).
The reasons list shows exactly which elements contribute to the score.
Step 7: Compare Different Queries
Try pasting a simpler query to see a lower score:
SELECT name, email FROM users WHERE active = 1
This scores around 10 (Simple) โ a single-table query with no joins or aggregation.
Step 8: Use the Other Modes
Switch to the Validate tab to check for syntax errors, or the Format tab to clean up the SQL formatting. All three tools share the same editor, so you can validate, format, and explain a query without re-pasting it.
Ready to explain your own queries?
Open Query ExplainerRelated Tools & Guides
Further reading: MySQL โ EXPLAIN Output Format ยท SQLite โ EXPLAIN QUERY PLAN
