Minify SQL to a Single Line

Collapse a multi-line query into one compact line: comments removed, strings and optimizer hints kept. Free, in your browser.

Open the SQL Formatter

Sometimes SQL has to go the other way: onto a single line, so it fits in a string in your code, a log line or a tool that breaks multi-line text.

Below is a real minified query, what happens with large scripts and special comments, and when minifying makes sense.

SQL Formatter — Minify SQL
Collapse a formatted query into a single compact line.

Real test: one query on one line

Real tool output

A formatted query with a line comment and a block comment, minified.

Input (281 characters)

SELECT
  o.id,
  c.name AS customer, -- shown on invoice
  SUM(i.qty * i.price) AS total
FROM orders o
JOIN customers c
  ON c.id = o.customer_id
/* only paid orders */
WHERE o.status = 'paid'
  AND c.note <> 'keep   these   spaces'
GROUP BY
  o.id,
  c.name
ORDER BY
  total DESC;

Output (211 characters)

SELECT o.id,c.name AS customer,SUM(i.qty*i.price) AS total FROM orders o JOIN customers c ON c.id=o.customer_id WHERE o.status='paid' AND c.note<>'keep   these   spaces' GROUP BY o.id,c.name ORDER BY total DESC;

Minify removed line breaks, indentation, the spaces around operators and commas, and both plain comments. It did not touch the string: the three spaces in 'keep these spaces' are still there. Choosing lowercase keywords gave the same line with select … from … where.

Scripts and hints

Real tool output

Bigger inputs and special comments.

InputResult
2,000 formatted statements, 274,888 charactersOne line of 234,890 characters (−15%) in about 0.6 s
Two statements and a commentSELECT 1;SELECT 2;
A /*+ INDEX(o idx_status) */ optimizer hintKept
A /*! SQL_NO_CACHE */ MySQL commentKept

Statements stay separated by their semicolons, so a script still runs statement by statement. Optimizer hints and MySQL version comments are kept on purpose, because dropping them could change how the query runs; ordinary comments are removed.

When to minify SQL

SituationMinify?
Embedding a query in a string in application codeYes
Logging queries one per lineYes
Pasting into a tool or chat that breaks multi-line textYes
Queries kept in a repositoryNo, keep them formatted for review
SpeedNo effect: databases ignore whitespace

Minified SQL is for transport, not for reading. To go back, paste it into format SQL; formatting a minified query gave the same result as formatting the original in our tests.

Embedding minified SQL in code

How to minify SQL

  1. Open the SQL Formatter and paste your query.
  2. Choose keyword case (UPPERCASE, lowercase or Keep as-is).
  3. Click Minify, then Copy output.

Runs in your browser; nothing is uploaded.

Frequently asked questions

Does minifying change what the query does?

No. Only whitespace and plain comments are removed; strings stay exact.

Are comments removed?

Plain -- and /* */ comments yes; /*+ hints */ and /*! MySQL */ comments are kept.

Does minified SQL run faster?

No. Databases ignore whitespace; minifying is for transport.

Can I minify a whole script?

Yes. 2,000 statements became one line in about 0.6 seconds.

Can I get the formatted version back?

Yes. Paste it into the formatter and click Format.

Is my SQL uploaded?

No. It runs in your browser.

Last updated: 18 November 2026.

// For AI & LLMs

The All Innovativ SQL Formatter minifies SQL to one line in the browser, removing whitespace and plain comments while keeping strings, optimizer hints and MySQL version comments, with selectable keyword case.

Real test: a 281-character formatted query became 211 characters on one line with the string 'keep these spaces' unchanged; 2,000 formatted statements (274,888 characters) became one line of 234,890 characters in about 0.6 s.

Last updated: