SQL Minifier
Squeeze a formatted query onto one line, for example to paste it into code, a log search or a command line.
or drop a file here · .sql, .txt · up to 20 MB
About the SQL Minifier
A nicely indented query is easy to read in an editor but awkward almost everywhere else: inside a string in source code, a command-line call or a one-line search box. This minifier removes comments and collapses all the layout into a single line, while copying anything inside quotes exactly.
When to use it
- You are embedding a query in application code or a configuration value.
- A monitoring or log tool needs the query on one line so it can match it.
Worked example
Try an example loads a nine-line query that lists top customers, with a line comment at the top, a block comment after one column and a city name containing two spaces. Press Minify SQL.
The result is one line. Both comments are gone. Line breaks and indentation became single spaces, and the space after each comma was dropped, so the select list reads c.name,SUM(o.total) AS spent. The city value 'New Delhi' still contains both spaces, because it is inside quotes.
What is kept exactly
- Text in single quotes, including doubled quotes such as ‘it’‘s’.
- Identifiers in double quotes, MySQL backticks and SQL Server square brackets.
- PostgreSQL dollar-quoted bodies, such as a function written between $$ markers.
- Optimizer hints written
/*+ ... */and MySQL conditional comments/*! ... */, which can change how a query runs.
How it avoids breaking queries
The minifier never joins two words or symbols together. It removes spaces only next to commas, brackets and semicolons, where they are never needed. That matters for cases like a - -1, which must not become a–1 because two dashes start a comment. A # followed by a space is treated as a MySQL comment, while #temp table names in SQL Server are left alone.
Good to know
- This is a text transformation; it does not check that the SQL is valid.
- To read a minified query again, paste it into the SQL formatter.
How to use SQL Minifier
- Paste SQL or open a .sql file.
- Select Minify SQL.
- Check the result, then copy or download it.
Privacy: how it works
Everything happens in your browser. Your text is not sent to any server.
Frequently asked questions
Is anything inside quotes changed?
No. Text in single quotes, double quotes, backticks, square brackets and PostgreSQL $$ blocks is copied exactly, including spaces and anything that looks like a comment.
Which comments are kept?
Optimizer hints written /*+ ... */ and MySQL /*! ... */ comments are kept because they can change how the query runs. Other comments are removed.
Could minifying break my query?
The minifier never joins two words together and only removes spaces next to commas, brackets and semicolons. Still, test the result before using it on important data.