SQL Minifier
Remove comments and extra whitespace from SQL to get a compact one-line query. Strings, quoted names and optimizer hints are left exactly as written.
SQL Minifier: the tool
Input
Minified SQL
The result appears here.How to use SQL Minifier
- Paste your SQL, or press Example.
- Choose the dialect so that strings, quoted names and comments are recognised the way your database reads them.
- Leave Remove comments on to drop them. Optimizer hints and MySQL conditional comments are always kept, because they change what the database does.
- Copy the one-line result or download it as a .sql file.
Example
The same report query, with its line comment removed.
select u.id, u.name, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = true and o.created_at >= '2026-01-01' -- recent orders only group by u.id, u.name having count(o.id) > 2 order by orders desc limit 10;
select u.id,u.name,count(o.id)as orders from users u left join orders o on o.user_id=u.id where u.active=true and o.created_at>='2026-01-01' group by u.id,u.name having count(o.id)>2 order by orders desc limit 10;
About this tool
Minifying SQL means removing what the database ignores: line breaks, indentation, repeated spaces and comments. The result is smaller and fits on one line, which is useful for logs, configuration files, query strings and embedding in code.
A careful minifier has to understand SQL's quoting first. Text inside 'single quotes', "double-quoted" names, `backticks`, [brackets] and $$dollar quotes$$ must never be changed, and a -- inside a string is not a comment. This tool tokenizes the query for the dialect you select, and then writes the tokens with the fewest spaces that still cannot merge two tokens into one: a space is kept between two operator characters, so that a - -b is never read as a--b.
A -- line comment would swallow the rest of a one-line query, so when you choose to keep comments they are rewritten as /* block */ comments. Hints such as /*+ INDEX(t i) */ and MySQL's /*! ... */ comments are executed by the database, so they are never removed. A unit test checks that the minified query has exactly the same tokens as the original in every dialect.
Frequently asked questions
Can minifying change the result of my query?
No. Only whitespace and comments are removed, and tokens are never merged. Hints and conditional comments are kept, because they are not ordinary comments.
Does the dialect matter for minifying?
Yes, for reading comments and quotes correctly. In MySQL, # starts a comment and -- needs a space after it, backslash escapes work inside strings, and in PostgreSQL # is an operator and dollar quoting exists. Selecting the right dialect avoids removing something that was not a comment.
Why are my line comments turned into block comments?
Only when you keep comments. A -- comment ends at the next line break, and a one-line query has none, so the comment would swallow the rest of the query. A block comment is equivalent and safe on one line.
Is a smaller query faster?
No. The database parses the same statement either way. Minifying helps with size in logs, payloads and configuration, not with execution time.
What about very long scripts?
Scripts of several megabytes are processed in your browser, and statements separated by semicolons are kept in order. Nothing is uploaded.
More developer tools
- sqlSQL FormatterFormat SQL queries for 12 dialects, with the keyword case and indentation you prefer. Comments are kept, and strings are never touched.
- {}JSON MinifierRemove every optional space and line break from JSON to make it as small as possible, without changing a single value.
- cssCSS MinifierRemove comments, whitespace and the last semicolon of every block from CSS. The result behaves exactly like the original.
- <//>HTML MinifierReduce the size of HTML by removing comments and collapsing whitespace. Pre-formatted text, scripts and conditional comments are left alone.