SQL Minifier
Minify SQL online: remove -- and /* */ comments and extra whitespace, never changing string literals or quoted names. See the bytes saved. Free and private.
How to use SQL Minifier
- 1Paste your SQL or open a .sql file and choose the dialect, because comment rules differ between databases.
- 2Read the one-line result and the bytes saved.
- 3Copy or download it, or switch Mode to Format or Validate to continue with the same query.
What makes it better
- Strips -- line comments, /* */ block comments and # comments (MySQL, MariaDB, BigQuery)
- Never edits inside 'strings', "quoted" and `backtick` names, [bracketed] names or $$dollar-quoted$$ text
- Keeps /*! MySQL conditional */ comments and /*+ optimizer hint */ comments on purpose
- Shows original size, minified size and the percentage saved
- Validate mode reports unclosed quotes, comments and parentheses with line and column
About SQL Minifier
SQL Minifier removes comments and collapses whitespace so a query fits on one line, using its own tokenizer that knows where strings, quoted identifiers and dollar-quoted blocks begin and end. Text inside them is copied byte for byte, and MySQL conditional comments and optimizer hints are kept because they change behaviour. It shows how many bytes you saved, and the page also formats and validates the same SQL.
Common uses
- Shrink a long query embedded in application code, a config file or a URL parameter.
- Strip internal comments from a query before pasting it into a ticket or sharing it outside the team.
- Put a multi-line query on one line for a shell command or a log search.
- Check that a MySQL dump line with a /*! conditional comment survives minifying.
Example
Input
-- Monthly revenue report
SELECT c.name ,
SUM(o.total) AS revenue /* paid orders only */
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE o.status = 'paid -- not a comment'
AND o.created_at >= '2026-01-01'
GROUP BY c.name
ORDER BY revenue DESC; -- top customers first
Result
SELECT c.name,SUM(o.total) AS revenue FROM orders o JOIN customers c ON c.id=o.customer_id WHERE o.status='paid -- not a comment' AND o.created_at >= '2026-01-01' GROUP BY c.name ORDER BY revenue DESC;
Good to know
- This minifier tokenizes SQL but does not parse it, so it never checks that a query is valid and it does not shorten names or reorder anything. Only comments and whitespace go.
- The dialect matters: in MySQL, -- must be followed by a space to start a comment (so 5--3 is arithmetic), while # is a comment in MySQL, MariaDB and BigQuery but an operator or a temp-table prefix elsewhere.
- Whitespace inside a multi-line string is part of the string and is kept. Oracle q'[...]' alternative quoting is not recognised; use Validate to find out if a quote is left open.
SQL Minifier FAQ
How do I minify a SQL query?
Paste it, pick the dialect and copy the one-line result. Comments are removed and every run of spaces and line breaks becomes a single space, or nothing next to commas, semicolons and parentheses where that is safe.
Does minifying SQL change how it runs?
Not when it is done at token level: strings, quoted names and hints keep their exact text and comments have no effect on execution. The exception is a comment the database reads as an instruction, which is why /*! and /*+ comments are kept.
Why is a -- inside my string not removed?
Because it is part of the string value, not a comment. The tokenizer tracks open quotes, including doubled quotes like 'it''s' and backslash escapes in MySQL, so a comment marker inside quotes is data.
Are optimizer hints and MySQL conditional comments kept?
Yes. Comments starting /*+ (optimizer hints) and /*! (version-conditional MySQL code, common in mysqldump files) can change the plan or even execute code, so they are copied through as written.
Can it make the query smaller than whitespace and comments allow?
No, and that is deliberate. It does not rename aliases, drop optional keywords like AS or INNER, or rewrite expressions, because doing that needs a full parser for each database. Expect savings mainly on heavily commented or indented SQL.