Skip to content
ToolZone

SQL Minifier

Compress a formatted SQL query down into a single compact line, useful for embedding queries in application code or configuration files.

Runs in your browser. Nothing you enter or upload leaves your device.

Input
Minified output…

Removes -- and /* */ comments and collapses whitespace; quoted strings and identifiers are kept as written.

Keyboard shortcuts

Run the main action
⌘ / Ctrl + Enter
Copy the result
⌘ / Ctrl + Shift + Enter
Download the result
⌘ / Ctrl + S
Paste a file or image into file tools
⌘ / Ctrl + V
Search all tools
⌘ / Ctrl + K
Show these shortcuts
?

You can also drop files anywhere on the page.

About the SQL Minifier

The SQL Minifier squeezes a neatly formatted query into a single line, removing -- and /* */ comments along the way. Quoted strings and identifiers are kept exactly as written, so values like 'New York' don't change.

How it works

When Minify is selected, the input is trimmed and every run of whitespace, including newlines and tabs, is replaced with a single space. That alone puts the whole query on one line.

Next, any spaces directly before or after a comma, an opening parenthesis, or a closing parenthesis are removed, so "IN (1, 2, 3)" becomes "IN(1,2,3)". Keyword case is not changed in this mode, and nothing else in the query is rewritten.

How to use

  1. 1

    Paste your SQL query into the input box, or click Open file.

  2. 2

    Check the single-line result and the size cards.

  3. 3

    Click Copy or Download to use it.

Worked examples

Compressing a formatted SELECT

A readable query needs to go into a single-line config value.

Input
SELECT id, name FROM users WHERE id IN (1, 2, 3)
Result
SELECT id,name FROM users WHERE id IN(1,2,3)

Minifying an INSERT

Shortening an insert statement for a log line.

Input
insert into t (a, b) values (1, 2)
Result
insert into t(a,b)values(1,2)

Spaces around parentheses are removed, and the lowercase keywords are kept as typed.

Limitations
It is a text-based pass, not a full SQL parser, so unusual dialect syntax such as dollar-quoted strings isn't recognised. Keywords are not uppercased or otherwise normalized. To pretty-print a query instead, use the SQL Formatter.
Assumptions
Quoted strings use standard single or double quotes. Your database accepts no space between a keyword and a parenthesis, which standard SQL dialects do.
Privacy
Minification runs in your browser, and your query is not sent anywhere or saved.

Frequently asked questions

Does minifying a SQL query change its behavior?+

Not for typical queries, since databases ignore whitespace between tokens. Queries with -- comments or meaningful spaces inside string literals can change, so check those cases.

Why would I want to minify a query?+

To embed it in application code, a JSON or YAML value, a shell command, or a log line where a single line is easier to handle.

Does it make queries run faster?+

No. The database spends no meaningful time on whitespace. Minifying only changes how the text is stored and displayed.

Is "IN(1,2,3)" without spaces still valid SQL?+

Yes. Spaces around parentheses and commas are optional in SQL, so the minified form runs the same as the spaced version.

Can I get the readable version back?+

Yes. Click Format and the same input is shown with each clause on its own line.

Related tools