SQL formatter
Beautify SQL queries with one clause per line and indented columns, or minify them to one line.
Runs entirely in your browser. Your files never leave your device.
About this tool
Queries copied from logs, ORMs and old scripts are often squeezed onto one line, which makes a wrong join or a missing condition easy to miss. Paste the SQL and the formatter puts every clause on its own line, SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY, with the columns and the AND or OR conditions indented below, and subqueries indented one level deeper.
Keywords can be written in upper or lower case to match your team’s style, while table names, column names, quoted strings and comments are left exactly as they were. Minify does the opposite and packs a query onto a single line for a config file or a log search. It works with the common syntax shared by MySQL, PostgreSQL, SQLite and SQL Server.
How it works
- Paste one or more queries.
- Choose Format or Minify.
- Pick the keyword case and the indentation.
- Copy or download the result.
The formatter reads the query token by token and never executes it. Semicolons separate several statements with a blank line.
Worked example
A one-line query from a log, select u.id,u.name,count(o.id) from users u left join orders o on o.user_id=u.id where u.active=1 and o.created_at>'2026-01-01' group by u.id,u.name, comes out with each clause on its own line and both conditions indented under WHERE.
Laid out like this, the bug is visible: the condition on o.created_at in WHERE removes users without orders, silently turning the LEFT JOIN into an inner join. Moving it into the ON clause fixes it.
Good to know
- Format before reviewing a query: misplaced conditions and missing join keys stand out.
- Keep one style for keywords across a team; uppercase is the most common.
- Strings and comments are left untouched, so formatting never changes what the query does.