SQL Minifier
Collapse a formatted query into a compact single line. Comments and redundant whitespace are removed, while everything inside quotes is left exactly as it is.
- Runs in your browser
- No sign-up
- Free to use
How to use SQL Minifier
- Paste your SQL into the input editor.
- Choose whether to strip comments and whether each statement should go on its own line.
- Select Minify SQL.
- Copy the compact query into your code, configuration or command line.
SQL Minifier features
String-safe
Spaces, line breaks and comment-like text inside string literals and quoted identifiers are never changed.
Comment removal
Strips -- line comments and /* block */ comments.
Hints preserved
Optimizer hints and MySQL version comments are kept because they affect execution.
One line or one per statement
Produce a single line, or keep each statement on its own line.
Dialect neutral
Handles backticks, square brackets, double quotes and PostgreSQL dollar quoting.
Size report
Shows how many bytes were removed.
When to use SQL Minifier
- Embedding a query in application code or a JSON or YAML config value.
- Pasting SQL into a command-line client or a single-line input field.
- Removing explanatory comments before sharing a query.
- Normalising queries so that logs and caches treat identical statements alike.
SQL Minifier FAQ
Does minified SQL run faster?
No. The database parses both forms into the same plan. Minifying is about convenience: fitting a query on one line, embedding it in code, or removing comments.
Is it safe for strings that contain -- or /*?
Yes. The minifier recognises string literals and quoted identifiers first, so comment markers inside them are treated as ordinary text.
Why were some comments kept?
Comments of the form /*+ … */ are optimizer hints and /*! … */ are MySQL conditional statements. Removing them would change how the query behaves, so they are preserved.
Can I get the formatting back?
Use the SQL Formatter to re-indent a minified query. Comments that were removed cannot be restored.
Does it handle multiple statements?
Yes. Statements separated by semicolons are kept in order. Choose the one-statement-per-line option to keep them visually separate.
Minifying SQL without breaking it
Collapsing whitespace in SQL sounds trivial, but a naive find-and-replace corrupts queries. A string literal such as 'two spaces' must keep both spaces, a value containing -- must not be cut off as a comment, and removing the space in "a - -1" would create a comment marker. Doing this correctly requires reading the query the way a database does.
This tool scans the text into tokens: literals, quoted identifiers, comments and everything else. Only the gaps between tokens are compressed, to a single space where a separator is needed and to nothing next to commas and parentheses, where a space is never required.