Format SQL queries, beautify code, improve readability, fix indentation, and organize complex statements instantly online.
What this formatter actually does under the hood, with a worked example for each feature, plus answers to the questions we get asked most.
A regex-based formatter scans the raw query text for keyword-looking words anywhere in the string — including inside string literals and comments — and reformats around them blindly.
That breaks on queries like WHERE status = 'select all'
or -- remember to check the order by clause later,
where a real regex-based tool will treat the word inside the quotes
or the comment as an actual keyword and re-break the line around it.
This formatter reads the query character-by-character first, tagging
each piece as a string, comment, quoted identifier, or real keyword
before any formatting decision is made — so a keyword-looking word
sitting inside a string or comment is left completely untouched.
Each major clause — SELECT, FROM, WHERE, GROUP BY, ORDER BY, and every JOIN variant — starts on its own new line, regardless of how the original query was written.
A flattened query like
select u.id,u.name from users u left join orders o on u.id=o.user_id where u.active=1
becomes:
Note the ON condition gets its own indented line under
the join it belongs to, rather than trailing on the same line — this
is what makes multi-join queries readable once you have three or
four tables joined together.
A nested SELECT inside parentheses is detected
automatically and indented one level deeper than the query that
contains it.
WHERE id IN (select user_id from banned_users where active=1) becomes:
A plain parenthesis that isn't a subquery — like a function call's
argument list — is left inline instead, so you don't end up with
every COUNT(id) broken across three lines.
Long WHERE conditions chained with AND or
OR can be broken onto their own indented lines, and
CASE ... WHEN ... THEN ... ELSE ... END blocks are
structured the same way.
WHERE status='active' AND created_at>='2026-01-01' AND role != 'guest'
with the "Break AND / OR onto new lines" option checked becomes:
Switching to Minify mode collapses a formatted query back into a single compact line, with the same tokenizer protecting string and comment content along the way.
This is the opposite direction of formatting — useful when you're pasting a query into application code, a log line, or a config file where a multi-line block isn't practical, and you want it condensed without breaking a string that happens to contain spaces or punctuation.
Before rendering output, the tool checks whether every opening parenthesis has a matching close and every string literal has a proper closing quote, and flags it if not.
Paste a query missing a closing parenthesis on a subquery, and instead of silently producing malformed output, the tool shows a warning like "Unbalanced parentheses detected (1 unclosed '(')" — a check most free online SQL formatters skip entirely, leaving you to spot the mistake yourself in the output.
Built on a real tokenizer, not a regex — text inside quotes or comments is never mistaken for a keyword.
Joins, subqueries, and CASE blocks are indented based on their actual nesting, not just line-by-line guesswork.
Unbalanced parentheses or unterminated strings are surfaced as a warning instead of silently producing bad output.