Tools

SQL Query Analyzer

Paste a query and see it taken apart — statement type, tables, columns, joins and conditions, each clause explained in a sentence, plus the query re-formatted and graded warnings. Handles SELECT , INSERT , UPDATE and DELETE .

Try
SELECT

SELECT statement on USERS, ORDERS with 1 JOIN, 3 aggregates, 1 condition

Tables
2
Columns
3
Selected
Joins
1
Conditions
1
In WHERE
Aggregates
3
Formatted
SELECT u.name, COUNT(o.id) AS orders, SUM(o.total) AS spend
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE u.created_at > '2024-01-01'
GROUP BY u.name
HAVING COUNT(o.id) > 3
ORDER BY spend DESC
LIMIT 20;
Tables
USERSORDERS
Selected columnsCapped at ten
U.NAMECOUNT(O.ID) → ORDERSSUM(O.TOTAL) → SPEND
Aggregates
COUNT(o.id)SUM(o.total)COUNT(o.id)
WHERE conditionsSplit at the top level
u.created_at > '2024-01-01'
Joins
JOIN orders ON u.
Clause by clauseWhat each part of the query does
SELECT
u.name, COUNT(o.id) AS orders, SUM(o.total) AS spend

Specifies which columns or expressions to include in the result set.

FROM
users u

Identifies the source table(s) to query. Multiple tables separated by commas create a Cartesian product.

JOIN JOIN
JOIN orders ON u.

Combines rows from two tables based on a related column.

WHERE
u.created_at > '2024-01-01'

Filters rows before aggregation. Only rows satisfying all conditions are included.

GROUP BY
u.name

Collapses rows with the same values in the specified columns into summary rows, enabling aggregate functions.

HAVING
COUNT(o.id) > 3

Filters groups after aggregation (like WHERE but for GROUP BY results).

ORDER BY
spend DESC

Sorts the final result set. ASC is ascending (default), DESC is descending.

LIMIT
LIMIT 20

Caps the result at 20 rows — useful for pagination.

Share

marduc812

© 202620260824_1c411cc