SQL Formatter
Paste a messy or one-line SQL query: SELECT, FROM, WHERE and the other clauses go on their own lines, columns and conditions line up, and subqueries are indented. Keywords can be upper- or lower-cased. Your query never leaves your browser.
This tool runs entirely in your browser; what you enter is never sent to our servers.
How to use it
- Paste your SQL query on the left.
- Choose keyword case and indent width, then press Format.
- Copy the formatted query, or use Minify for a single line.
Why format SQL?
A long query on one line is hard to follow: it is easy to miss which tables are joined or which condition filters what. The formatter puts each clause (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY, LIMIT) on a new line, lists columns and AND/OR conditions one per line, and indents subqueries inside their parentheses. Only whitespace and keyword case change: strings ('…'), quoted names ("…", `…`, […]) and comments stay exactly as written, so the query means the same thing. Several statements separated by semicolons get a blank line between them. Minify puts the query on one line and removes comments (a -- comment would otherwise swallow the rest of the line). The tool understands the syntax shared by MySQL, PostgreSQL, SQL Server, SQLite and Oracle; database-specific commands pass through unchanged.