select id, name, email from users where active = 1 order by name;SQL Minifier
Less whitespace. The same tokens. Compact SQL while preserving strings and meaningful comments.
SQL Input
Minified SQL Output
Ready when you are. Paste a query to get started.
Send Feedback1 MB input limit · No database connection required
START WITH SOMETHING SMALL
SQL examples
Load an example, then make it yours.
select u.name, o.total from users u join orders o on u.id = o.user_id where o.total > 100;select name from users where id in (select user_id from orders where total > 100);select name, case when total > 100 then 'Priority' else 'Standard' end as tier from orders;with recent_orders as (select user_id, total from orders where total > 100) select user_id, sum(total) from recent_orders group by user_id;Compact whitespace without deleting the SQL between it
This SQL minifier uses the tokenizer from sql-formatter 15.10.0 to distinguish quoted strings, identifiers, keywords and comments. It reduces whitespace between tokens to a single separator where appropriate. It preserves token text rather than rebuilding your statement from a database syntax tree.
How to minify SQL
Paste SQL or upload a .sql or .txt file, select the matching dialect and click Minify SQL. Review the compact output, then copy it or download a .sql file. The character counters let you compare input and output. Already compact SQL may not become shorter, especially when it contains substantial literal text or comments.
Strings and comments are part of the query
Spaces inside a string such as 'New York' remain intact. Quoted identifiers retain their spelling. Comments are preserved because optimizer hints and executable comments can carry meaning. Line comments keep the following newline so they do not swallow the next statement. Newlines between adjacent string tokens are retained when present, which matters for PostgreSQL string concatenation syntax.
The output can therefore contain line breaks. Safe compaction is more useful than forcing every statement onto one line. Whitespace inside a token, including a multiline literal or a recognized multiword keyword token, is preserved. This conservative approach may save fewer characters than a destructive whitespace replacement.
A consistency check after compaction
The worker tokenizes the result again and compares token count, token types and raw token text against the original. If those differ, the operation fails instead of returning a success result. This is a token preservation check; it is not a claim that every SQL program has been semantically proved equivalent. Use the proper dialect and review production changes.
Minification is not optimization or validation
Shorter source code does not automatically run faster in a database. This tool does not change a query plan, remove joins or rewrite expressions. It also does not fully validate SQL grammar. For a parser-based grammar check, use SQL Validator. For a readable version of compact SQL, use the SQL Formatter or compare beautifier presets.
Working limits
The input limit is 1 MB and long operations time out. Malformed quoted strings or unknown tokens can fail during tokenization. Your original input remains available after an error. Processing occurs in a worker in this page; code dependencies load from a CDN. No query history is stored by the tool. Visit All Tools for the full collection.
A FEW MORE SHORTCUTS
Keep your workflow moving
GOOD TO KNOW
Frequently asked questions
Why does the output still contain newlines?
Line comments need a terminating newline. Newlines between adjacent SQL string tokens may also be significant and are retained.
Does this remove SQL comments?
No. Comments can contain optimizer hints or executable SQL, so this minifier preserves them.
Will minifying make my query faster?
Not necessarily. It reduces source whitespace and does not optimize the execution plan.
Is the minified query syntax-validated?
Token preservation is checked. Full grammar validation is separate; use SQL Validator and test against your database.
