How the SQL minifier works
This tool does not use a SQL parser or an external library. It uses a small character scanner that runs in your browser and walks through the query once, left to right:
-- starts a line comment. Everything up to the end of the line is dropped.
/* starts a block comment. Everything up to the next */ is dropped.
- A
', ", or ` starts quoted text, which is copied as is until the matching closing quote. Backslash escapes and doubled quotes such as 'it''s' are handled, so comment markers inside quotes are left alone.
- Any run of spaces, tabs, and newlines outside quotes becomes one space.
After the scan, a clean-up pass removes spaces next to ; , ( ) = < and >. With Keep statement ; unchecked, semicolons at the very end are also removed. You can press Ctrl + Enter in the input editor instead of clicking Minify.
Worked example
-- Active customers with paid orders this year
SELECT c.id,
c.email,
COUNT(o.id) AS order_count /* paid only */
FROM customers c
JOIN orders o ON o.customer_id = c.id
WHERE o.status = 'paid'
AND o.created_at >= '2026-01-01'
GROUP BY c.id, c.email
ORDER BY order_count DESC;
Output:
SELECT c.id,c.email,COUNT(o.id)AS order_count FROM customers c JOIN orders o ON o.customer_id=c.id WHERE o.status='paid' AND o.created_at>='2026-01-01' GROUP BY c.id,c.email ORDER BY order_count DESC;
Both comments are gone and the query fits on one line. COUNT(o.id)AS looks odd but is valid, because databases split tokens at the parenthesis. One-line SQL is handy in a JSON or YAML config value, an environment variable, or a log line you want to grep.
Why comments matter when SQL goes on one line
A -- comment ends at the line break. Join the lines naively and the comment runs to the end of the whole query, silently disabling everything after it. This minifier removes comments before collapsing whitespace to avoid that, but it only knows the standard comment styles.
Real risks, and how to avoid them
1. MySQL # comments are not recognized
SELECT id FROM users # legacy filter
WHERE active = 1;
becomes SELECT id FROM users # legacy filter WHERE active=1;. MySQL now treats WHERE active=1; as part of the comment and returns every user. Change # comments to -- (with a space after the dashes) before minifying.
2. Text inside quotes can change
The clean-up pass runs over the whole output, including quoted text. WHERE note = 'Hello, world (a = b)' becomes WHERE note='Hello,world(a=b)', which no longer matches the stored value. Runs of plain spaces inside quotes are kept, but spaces next to , ; ( ) = < > are not. Use bound parameters for values like these, or check the output.
3. Hints and executable comments are removed
Oracle and MySQL optimizer hints such as /*+ INDEX(t idx_status) */ and MySQL version comments such as /*!50100 ... */ look like block comments, so they are deleted. The query still runs, but the hint no longer applies.
4. Double dashes without a space
In MySQL, -- only starts a comment when a space follows, so SELECT 5--3 means 5 minus negative 3. This tool treats any -- as a comment and outputs SELECT 5. Write 5 - -3 instead.
Other limitations
- No validation. Invalid SQL is minified without a warning.
- PostgreSQL dollar-quoted bodies (
$$ ... $$) are not treated as strings. Their contents are minified like normal SQL.
- T-SQL bracket identifiers are not treated as quotes, so
[Order Date] with two spaces becomes [Order Date].
- With PostgreSQL's default string rules, a backslash is an ordinary character. A literal that ends in a backslash, like
'C:\', makes the scanner think the string continues, so the text after it may be left unminified.
- Keyword case and identifier names are never changed.
When to use a different tool
- To make a one-line query readable again, use the SQL Formatter.
- If the query travels inside an API payload, check the surrounding document with the JSON Validator.
- To embed the query in a PHP script, open the PHP Editor.
Frequently asked questions
Is it safe to minify SQL queries that contain strings?
Partly. The minifier recognizes single-quoted, double-quoted, and backtick-quoted text, so comment markers such as -- inside a string are not treated as comments. However, a final clean-up pass removes spaces next to commas, semicolons, parentheses, =, <, and > everywhere, including inside strings. A value like 'Hello, world' becomes 'Hello,world'. Check the output if your literals contain those characters.
Will minified SQL still run the same way?
Usually, yes, for queries that use -- and /* */ comments. The exceptions are MySQL # comments, which are not recognized and end up commenting out the rest of the one-line query, optimizer hints written as /*+ ... */ and MySQL /*! ... */ comments, which are removed, and string values that contain spaces next to punctuation.
What does the "Keep statement ;" option do?
When it is checked, the output keeps its semicolons. When it is unchecked, only the semicolons at the very end of the output are removed. Semicolons between statements are always kept, so several statements stay separated.
Can I turn minified SQL back into a readable query?
Yes, paste it into the SQL Formatter to restore line breaks and indentation. Comments removed by the minifier cannot be recovered, so keep the original query if the comments matter.
Does this tool send my SQL anywhere?
No. Minification runs in your browser with a small built-in scanner, and nothing is executed against a database. The SQL you paste is not saved by the page; only display preferences such as the editor theme are stored in local storage.