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.
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?
- No. Only comments and whitespace outside of strings and quoted names are removed, so the database parses and runs the query exactly as before.
- 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.