SQL Minifier

Paste SQL to strip comments and whitespace and get a compact one-line query. The result updates as you type.

What does a SQL minifier do?

A SQL minifier removes everything the database does not need: -- line comments, /* block comments */, line breaks, indentation and the spaces around commas and brackets. The query does exactly the same thing, but fits on one line.

That is handy when you need to embed a query in a JSON config, an environment variable, a log message or a string in code, or when you want to paste it into a single-line field. Text inside 'string literals', "quoted", `backtick` and [bracket] names and PostgreSQL $$ bodies is never changed.

Some comments change what a query does, so they are kept: optimizer hints such as /*+ INDEX(...) */ and MySQL executable comments such as /*!80000 ... */. Where joining two lines could change the meaning (a MySQL # comment, -- directly followed by text, or a T-SQL GO line), the line break is kept. Choose MySQL / MariaDB or the other databases above the input, because only MySQL treats \' inside a string as an escaped quote.

Example

Before:

-- Active customers with their order count
SELECT c.id,
       c.name,
       COUNT(o.id) AS orders   /* includes cancelled */
FROM   customers c
       LEFT JOIN orders o ON o.customer_id = c.id
WHERE  c.active = 1
GROUP  BY c.id, c.name;

After minifying:

SELECT c.id,c.name,COUNT(o.id) AS orders FROM customers c LEFT JOIN orders o ON o.customer_id = c.id WHERE c.active = 1 GROUP BY c.id,c.name;

Need to read a one-line query instead? Use the SQL formatter to expand it back into readable, indented SQL.

Frequently asked questions

Does minifying change what my query does?
It shouldn't. Only comments and whitespace outside strings and quoted names are removed; optimizer hints and MySQL executable comments are kept, and a line break is kept wherever joining lines could change the meaning. Pick the right database above the input so backslashes in strings are read correctly.
Will it break strings that contain -- or /*?
No. The minifier reads the query character by character and skips over string literals and quoted identifiers, so comment-like text inside them is kept.
Does a minified query run faster?
Not in any way you would notice — the database parses it once either way. Minifying is about making the query compact to store, embed or send, not about speed.
Which databases does it work with?
Any SQL database: MySQL, MariaDB, PostgreSQL, SQL Server, Oracle and SQLite all use the same comment and whitespace rules.
Is my SQL uploaded anywhere?
No. The minifier runs entirely in your browser, so your queries never leave your computer.

Related tools