Output appears here.
The SQL Minifier compresses a formatted query onto a single line by removing line breaks, indentation and comments, while leaving strings, quoted identifiers and placeholders exactly as written. Use it to embed SQL in config files, environment variables, log lines or code strings. Everything runs in your browser — nothing is uploaded.
How to minify SQL
- Paste one or more statements, drop a
.sqlfile, or choose Load example. - Decide whether comments matter. By default they are removed; turn on Keep comments to carry them into the single line as
/* */blocks. - Copy the one-line query with ⌥/Alt C, or use the Format Next action to expand it again in the SQL Formatter.
Examples
Formatted query with a trailing comment
The default settings remove the comment and collapse the whitespace.
SELECT
id,
name -- display name
FROM
users
WHERE
active = 1;Result:
SELECT id,name FROM users WHERE active = 1;Keeping comments
The same query with Keep comments on. The -- comment is rewritten as a block comment, because a line comment would swallow the rest of a one-line query.
SELECT
id,
name -- display name
FROM
users
WHERE
active = 1;Result:
SELECT id,name /* display name */ FROM users WHERE active = 1;Strings and named parameters are untouched
Whitespace inside the string literal survives, and :min_total stays attached to its comparison.
-- monthly revenue
SELECT
status,
count(*) AS n
FROM
orders
WHERE
note <> 'needs review'
AND total >= :min_total
GROUP BY
status;Result:
SELECT status,count(*)AS n FROM orders WHERE note <> 'needs review' AND total >= :min_total GROUP BY status;SQL Server identifiers with spaces
Bracketed names containing spaces are treated as single tokens.
SELECT [Order Id], [Customer Name]
FROM dbo.[Order Details]
WHERE qty > 0
AND price * qty >= 100;Result:
SELECT [Order Id],[Customer Name] FROM dbo.[Order Details] WHERE qty > 0 AND price * qty >= 100;Options explained
- Dialect — names the database the query targets. Single-quoted strings, double-quoted, backtick and bracketed identifiers, and PostgreSQL dollar-quoted strings are recognized in every dialect. The setting matters for
#: with MySQL or MariaDB, a#anywhere on a line starts a comment, while other dialects treat#as a comment only at the start of a line. - Keep comments — keeps
--,#and/* */comments in the output, converting line comments to block comments so the single line stays valid.
Common problems when compressing SQL
A MySQL # comment was kept as text
A # after code on the same line, as in select a, # note, is a comment only in MySQL and MariaDB. With another Dialect, it is treated as text and joined to the next line. Set Dialect to MySQL or MariaDB, and the comment is removed, or kept as /* note */ with Keep comments on.
The query stopped working after pasting it into code
Most languages need the query inside a string, and the quotes in the SQL must then be escaped for that language. The minifier does not add escapes. If the destination is JSON, run the line through JSON Escape to get a valid string literal.
A string lost its line breaks
It did not — whitespace inside quoted strings is kept exactly. If a string appears to have changed, check whether it was closed properly in the input: an unmatched quote makes the rest of the query part of the string.
Comments disappeared
Comments are removed by default because they are the most common reason a one-line query breaks. Turn on Keep comments to preserve them as /* */ blocks.
The saving looks small
Queries that are already compact save only a few percent. The largest savings come from formatted SQL with deep indentation and comments, often 30–40%.
FAQ
Why minify SQL at all?
A single-line query is easier to place inside a YAML or .env value, a Java or Python string, a log message or a CSV cell, and it keeps a query intact when a tool splits text by lines. Minifying is not usually about performance: databases parse whitespace quickly, so the gain is in portability, not execution speed.
Does minifying change what the query returns?
The minifier only removes whitespace that has no meaning and, optionally, comments. It keeps at least one space between words, so SELECT a FROM t never becomes SELECTa, and it does not touch literals, identifiers or parameters. The result runs the same way as the input on the same database.
How do I turn a one-line query back into readable SQL?
Use the Format Next action. It opens the query in the SQL Formatter, where you can choose a dialect, keyword case and indentation to beautify it again. Comments you removed while minifying cannot be restored, so keep a formatted copy if the comments matter.
Can I minify a whole migration file?
Yes. Paste the file or drop it on the editor. Every statement is compressed and the semicolons stay in place, so statements remain separate. The output is a single line, which suits embedding better than version control; keep the formatted file as your source of truth.
Is my SQL uploaded anywhere?
No. The minifier runs in your browser, in an isolated editor frame that blocks network requests, so internal table names and credentials inside a query never leave your device. Settings are remembered locally; your input is stored only if you turn on "Remember my last input".
Is there a difference between this and Minify mode in the SQL Formatter?
They use the same engine. The Minify mode in the formatter is a quick switch for a query you are already working on; this page adds the Keep comments option. Other compressors on the site include the JSON Minifier and the CSS Minifier.
What the minifier removes and keeps
The minifier works on tokens, not on raw text, which is why it is safe to run on real queries.
- Removed: line breaks, indentation, runs of spaces, and spaces next to punctuation such as commas and parentheses. Comments are removed unless you keep them.
- Kept: one space wherever two words or operators would otherwise merge, such as
WHERE activeor>= :min_total. Two minus signs are never joined, so5 - -3stays5 - -3rather than becoming a--comment. - Never touched: the contents of
'strings',"identifiers",`backticks`,[brackets],$$dollar-quoted$$bodies, and placeholders like?,$1,:nameand@p. - Not changed: keyword case and statement order. Minifying is not formatting in reverse; it does not re-case
selector reorder clauses. To normalize case first, format with the SQL Formatter and then minify.
Multiple statements stay separated by their semicolons on the same line, for example select a from t;select b from u;.