SQL formatter

Paste a query to get it laid out clause by clause with consistent keyword case.

Formatting rules

This is a keyword-based formatter, not a full SQL parser, so unusual dialect syntax (procedural blocks, CTE-heavy queries) is kept readable but may not be perfectly aligned.

Logical order of a SELECT

Written orderEvaluated order
1 SELECT5
2 FROM / JOIN1
3 WHERE2
4 GROUP BY3
5 HAVING4
6 ORDER BY6
7 LIMIT7

That order explains why a column alias defined in SELECT cannot be used in WHERE but can be used in ORDER BY.

Frequently asked questions

Does it change what my query does?
No. Only whitespace and keyword case change; identifiers, strings and operators stay the same.
Uppercase or lowercase keywords?
Purely style. Uppercase keywords are traditional and make clauses stand out; many teams now prefer lowercase. Pick one and stay consistent.