SQL Formatter/Minifier

Beautify or minify a SQL query - free, no signup.

SQL formatter / minifier
Mode
Result

What this tool does

Paste your SQL and switch between Format (puts each major clause - SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY - on its own line, indents AND/OR conditions, and splits SELECT columns onto separate lines) and Minify (collapses everything to a single compact line). Column splitting tracks parenthesis depth, so a comma inside a function call like COUNT(a, b) is never mistaken for a column separator.

Formats a SQL query by putting each major clause on its own line and indenting AND/OR conditions beneath WHERE, ON or HAVING.

Splits a SELECT clause's columns onto separate lines, correctly skipping over commas that are inside a function call's parentheses.

Optionally uppercases SQL keywords for consistency, and minifies a query down to a single compact line for pasting elsewhere.

Minifies by stripping both -- line comments and /* */ block comments before collapsing all remaining whitespace to single spaces.

Matches every recognized clause keyword in one longest-first pass, so a two-word clause like LEFT JOIN can't be split apart by a shorter keyword's own separate pass.

How to use it

  1. Paste your SQL query.
  2. Choose Format to beautify it, or Minify to compact it.
  3. Copy the result or download it as a file.

Why use this formatter

Long queries are hard to read on one line, and reviewing joins and conditions needs structure. Breaking clauses onto lines makes queries easier to check.

Why we built it

We built the SQL formatter to split SELECT columns onto separate lines while tracking parentheses, so a comma inside COUNT(a, b) is not broken. Convert data with the JSON to CSV converter and the CSV formatter.

Related tools worth a look: the JavaScript Formatter/Minifier.

Who this tool is for

  • Developers and analysts reading long queries
  • DBAs tidying scripts
  • Students learning SQL

When to use it

  • Reviewing or sharing a query.
  • Cleaning ORM or log output.
  • Compacting a query.
  • Reading nested conditions.

Why comma-splitting needs to track parentheses

Not every comma in a SELECT clause separates two columns.

A SELECT clause like 'SELECT id, COUNT(orders.id), name' has three commas total, but only two of them actually separate columns - the comma inside COUNT(orders.id) is a function argument separator, not a column separator, and splitting on it would break the query into invalid fragments. This formatter tracks how deep it is inside parentheses as it scans the column list, and only treats a comma as a column separator when it's outside of any parentheses - so a function call's own arguments always stay together on one line.

Why keyword order matters in a clause-matching pattern

Splitting a two-word clause like LEFT JOIN takes one careful pass, not several sloppy ones.

Recognized clauses include both single-word keywords like JOIN and multi-word ones like LEFT JOIN, RIGHT OUTER JOIN and UNION ALL. If a formatter ran a separate find-and-replace pass for each keyword one after another, a later plain JOIN pass would re-scan text a LEFT JOIN pass had already newlined, match the word JOIN inside it, and split LEFT JOIN into LEFT on one line and JOIN on the next. This tool avoids that by combining every recognized clause into a single regular expression, sorted longest-first, so at any given position in the query the longer match wins before a shorter keyword ever gets a chance to match inside it.

What you give it, and what you get back

Input and output of SQL Formatter/Minifier
ItemDetails
InputA SQL query.
ModeBeautify or minify.
OutputClauses on separate lines, or a compact query.

Issues you may run into

Common problems with SQL Formatter/Minifier
What you seeWhy it happensWhat to do
Dialect syntax breaks oddlyVendor-specific clauses may not match.Edit by hand.
The query is wrongIt does not validate SQL.Run it in a test database.
Comments are lost when minifyingThey are stripped.Keep the formatted version.

Assumptions and limitations

Frequently asked questions

How do I format a SQL query online for free?

Paste your query with Format mode selected, and it's broken onto readable, indented lines by clause instantly.

How do I minify SQL online for free?

Paste your query with Minify mode selected - it's collapsed to a single compact line with comments removed.

Does minifying remove SQL comments?

Yes - both -- line comments and /* */ block comments are stripped during minification, in addition to collapsing all whitespace to single spaces.

Will a two-word clause like LEFT JOIN ever get split across two lines?

No - every recognized clause keyword is matched in a single combined pass ordered longest-first, so LEFT JOIN is matched and newlined as one unit before a plain JOIN pattern could ever match inside it.

Will this break a comma inside a function call, like COUNT(a, b)?

No - the formatter tracks parenthesis depth while splitting SELECT columns, so a comma inside a function call's arguments is never mistaken for a column separator.

Can I keep my keywords in lowercase?

Yes - turn off 'Uppercase keywords' before formatting to keep your original casing.

Is my query uploaded anywhere?

No. Formatting and minifying happen entirely in your browser - nothing is sent to a server, and closing the tab clears it.