How to use the SQL minifier
- Paste your query or script into the SQL box. The sample has line comments, a block comment and a string containing
--. - Tick Treat # as a comment (MySQL) if your SQL is for MySQL or MariaDB.
- Copy the Minified SQL. Saved, Original and Minified show the size change in bytes.
What it does and when to use it
A query that reads well in an editor is often awkward elsewhere: inside a string in application code, in a JSON config, in a shell command, in a log line or in a URL parameter for a dashboard tool. Minifying puts it on one line and strips comments that might contain internal notes. It is also a quick way to compare two queries that differ only in layout.
To go back to a readable layout, use the SQL formatter. The XML minifier and CSS minifier do the same job for other formats.
How it works
The minifier reads the SQL one character at a time in your browser and tracks where it is:
--to the end of the line is a comment, and so is#when the MySQL option is on./* … */is removed unless it starts with/*+or/*!.- Quoted text in
'…',"…",`…`and[…]is copied whole, including doubled quotes such as'it''s'. - PostgreSQL dollar-quoted bodies,
$$ … $$or$tag$ … $tag$, are copied whole, comments and line breaks included. - Any run of whitespace becomes one space. That space is dropped after
,(;=and before,);=.
Worked examples
These are the tool’s own outputs.
The sample query. Seven lines with three comments become:
SELECT id,name FROM users WHERE note='keep -- this' AND created_at >='2026-01-01';
Saved: 45.5%, from 154 bytes to 84. The -- inside the string survives because it is not a comment there.
MySQL with # comments. SELECT name # MySQL note, FROM `users` and WHERE id IN (1, 2, 3); on three lines, with the MySQL option ticked, give SELECT name FROM `users` WHERE id IN (1,2,3);.
A PostgreSQL function. In CREATE FUNCTION f() RETURNS int AS $$ … $$ LANGUAGE sql; the body between the $$ markers keeps its line breaks and its -- body comment, because it is a string to the database. Nothing outside it needed changing, so the saving is 0%.
Limits and tips
- Keywords are not changed. Upper and lower case stay as you wrote them.
- No renaming or shortening of tables, aliases or values.
- Keep the readable version in your repository and minify copies for embedding.
Frequently asked questions
Can minifying change what my query does?
When should I tick "Treat # as a comment"?
Why does a space stay before >= but not after it?
Are optimizer hints kept?
Does it check my SQL?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.