Indent · Align · Structure
How to Indent SQL
Updated: June 2026
Good SQL indentation is not decoration — it is what makes a query readable. Here are the simple rules behind clean SQL layout, plus a one-click way to apply them to any query instantly.
Free · No upload · Instant in the browser
Why indentation matters in SQL
SQL ignores whitespace, which means a query can be written with no structure at all and still run. That is a trap. Without indentation, a query is a flat run of words where the boundaries between clauses are invisible and the relationship between a join and its condition is anyone's guess. Indentation restores that structure visually: it turns a sentence into an outline, where the shape of the layout mirrors the shape of the logic.
The payoff is faster reading and fewer mistakes. A well-indented query lets you confirm at a glance that every join has a condition, that filters are grouped correctly, and that a sub-query is nested where you think it is.
The core rules
- One clause per line.
SELECT,FROM,WHERE,GROUP BY,HAVINGandORDER BYeach begin a new line at the base margin. - Indent the clause body. The columns after
SELECT, the tables afterFROM, the conditions afterWHEREall sit one level in. - One item per line in lists. Each selected column and each
WHEREcondition gets its own line so long lists never scroll sideways. - Break on AND and OR. Starting each boolean on a new line makes the logic read like a checklist.
- Indent sub-queries deeper. A query inside parentheses is indented one level beyond its parent so nesting is obvious.
Rules applied
SELECT
c.name,
o.total
FROM
customers c
JOIN orders o
ON o.customer_id = c.id
WHERE
o.status = 'paid'
AND o.total > 50
ORDER BY
o.total DESC
Every rule above is visible here: clauses at the margin, bodies indented, one item per line, booleans broken out, the join paired with its condition. This is the layout a formatter produces automatically.
Let the tool do it
Knowing the rules is useful, but applying them by hand to a long query is tedious and error-prone. A formatter encodes all of these conventions and applies them in a single pass, consistently, every time — so you get textbook indentation without counting spaces. Paste your query, choose two-space or four-space indentation, and copy the result. It runs entirely in your browser, so even queries full of internal names stay private and the tool works with no connection at all.
Frequently asked questions
What is the standard way to indent SQL?
Put each major clause on its own line, indent the items belonging to that clause one level, and indent sub-queries one level deeper than their parent. Keywords are usually uppercased for contrast.
Should SQL use tabs or spaces?
Either works; consistency is what matters. Two spaces is compact and common, four spaces gives more visual separation for deeply nested queries. Pick one and apply it everywhere.
Do I have to indent SQL by hand?
No. A formatter applies the rules automatically and instantly. Paste your query and the tool indents every clause and sub-query for you, with no upload.