Formatting rules
- Each major clause (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT) starts on a new line.
- Selected columns are listed one per line, indented.
- JOINs start a new line; AND / OR conditions are indented under WHERE.
- Strings, quoted identifiers and comments are left untouched.
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 order | Evaluated order |
|---|---|
| 1 SELECT | 5 |
| 2 FROM / JOIN | 1 |
| 3 WHERE | 2 |
| 4 GROUP BY | 3 |
| 5 HAVING | 4 |
| 6 ORDER BY | 6 |
| 7 LIMIT | 7 |
That order explains why a column alias defined in SELECT cannot be used in WHERE but can be used in ORDER BY.