SQL Minifier

Strip comments and collapse whitespace to shrink a SQL query down to a single compact line, without changing its logic.

Input SQL

Minified SQL

SELECT id, name, email FROM users WHERE active = true AND created_at > '2025-01-01' ORDER BY created_at DESC LIMIT 20;

Strips comments and collapses whitespace onto one line, doesn't rename identifiers or change query logic.

Example input

SELECT *\nFROM users;

Example output

SELECT * FROM users;

What is a SQL Minifier?

A minified SQL query has all its comments removed and its whitespace collapsed down to the minimum needed to stay valid, turning a nicely formatted multi-line query into a single compact line. This doesn't change what the query does. It only removes formatting that exists purely for human readability, which is exactly what you want to strip out when a query needs to be embedded somewhere that treats line breaks awkwardly, like a single-line config value, a URL parameter, or a script that expects a query as one unbroken string.

When to use it

This comes up when pasting a query into a tool or config field that doesn't handle multi-line text well, when logging queries and wanting a compact single-line representation instead of a sprawling multi-line block cluttering the log output, or when embedding a query as a string literal in code where keeping it on one line is simpler than managing line continuation characters. It's the SQL equivalent of minifying JavaScript or CSS for a context where readability doesn't matter but compactness does.

How it works

The minifier strips out both line comments (starting with --) and block comments (wrapped in /* */), then collapses all runs of whitespace, including newlines and multiple spaces, down to single spaces. It also tidies spacing immediately around commas and parentheses so the result stays syntactically valid SQL, just without any of the original line breaks or indentation.

Frequently asked questions

Does minifying a SQL query change its behavior or results?

No. Minifying only removes comments and collapses whitespace, both of which have no effect on how the SQL query executes or what results it returns. The query's logic, table references, and conditions stay exactly the same.

Why would I minify a query instead of just leaving it formatted?

Minifying is useful specifically when a query needs to fit into a single-line context, like a URL, a config file value, or a compact log entry, rather than for everyday development where a well-formatted, readable query is almost always better to work with.

Can I reformat a minified SQL query back into a readable version?

Yes. Since minifying only removes whitespace and comments rather than renaming anything, a minified query can be run back through a SQL formatter to restore readable indentation and line breaks. This site's SQL Formatter tool does exactly that.