SQL Minifier
Compress SQL queries into a compact form for 13 dialects, or beautify them back
What is an SQL Minifier?
An SQL minifier removes line breaks, indentation, and extra spaces from a query so it fits in a compact form. The query does the same thing, but takes less space.
Compact SQL is handy when you embed a query in application code, store it in a log or config file, or paste it into a one-line field. This tool supports 13 SQL dialects and also includes Beautify, so you can switch back to an indented layout whenever you need to read the query.
How to Use This SQL Minifier
- Paste your SQL into the input box, or click Example to load a sample query.
- Select your Dialect. See the table below for why this matters.
- Click Minify SQL to compress the query, or Beautify to indent it.
- Check the size comparison. Original, Minified, and Saved show the result.
- Copy Result or use Download .sql.
Why the Dialect Matters
Databases quote identifiers and reserve keywords differently, so the tool needs to know which one you use to read your query correctly. If the dialect is wrong, valid SQL can produce a parse error.
| Dialect family | Quoting for names with spaces or reserved words | Example |
|---|---|---|
| MySQL, BigQuery | Backticks | `order` |
| PostgreSQL, SQLite, Oracle, DB2 | Double quotes | "order" |
| MSSQL, TSQL | Square brackets | [order] |
String values use single quotes in all dialects, for example '2026-01-01'. Available dialects: MySQL, PostgreSQL, SQLite, MSSQL, Oracle, DB2, PL/SQL, N1QL, TSQL, BigQuery, Redshift, Spark, and Trino.
Example: Before and After Minifying
Input (227 bytes).
SELECT u.id,
u.name,
COUNT(o.id) AS order_count
FROM users u
LEFT JOIN orders o
ON o.user_id = u.id
WHERE u.active = 1
AND o.created_at >= '2026-01-01'
GROUP BY u.id, u.name
ORDER BY order_count DESC
LIMIT 10;
Output with the MySQL dialect (209 bytes):
SELECT u.id, u.name, COUNT(o.id) AS order_count FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.active = 1 AND o.created_at >= '2026-01-01' GROUP BY u.id, u.name ORDER BY order_count DESC LIMIT 10;
| Metric | Value |
|---|---|
| Original | 227 bytes |
| Minified | 209 bytes |
| Saved | 18 bytes (7.9%) |
The query still reads the same, the string '2026-01-01' is unchanged, and keywords are written in uppercase.
Comments and String Values
Minifying changes spacing, not data. These are the cases that matter for real queries:
| Part of the query | After minifying |
|---|---|
| Indentation and line breaks | Collapsed to single spaces |
-- comment | Kept, and the line break after it is kept so it does not comment out the rest of the query |
/* comment */ | Kept inline |
Spaces inside 'a b' | Preserved exactly |
Placeholders such as ? | Preserved |
| Keyword case | Uppercased |
A query with line comments keeps one line per comment, so the output can span more than one line. If you need a strict one-line query, remove -- comments first or use /* ... */ comments.
Tips and Common Mistakes
- Line comments can swallow your query. A
--comment runs to the end of the line. The minifier keeps the line break after it, but if you join the lines yourself with another tool, everything after the comment can be lost. - String values stay exactly as written. Spaces inside quotes are data, for example
'a b'. The minifier preserves them. - Pick the right dialect. The wrong dialect can misread quoted names and non-standard syntax.
- Keep a readable copy. Store the formatted query in your repository and minify only the copy you embed or send.
- Test in your database. Run the minified query on a test database before you use it in production.
- Minifying does not make queries faster. The database parses the same statement. You only save space in code, logs, and network messages.
Common Use Cases
- Raw queries in application code: a one-line string is easier to embed.
- Logs and monitoring: one line per query.
- Configuration files and API payloads: compact SQL in JSON or YAML.
- Migration files: shorter statements.
- Sharing a query: paste it in chat or an issue without losing the line.
Frequently Asked Questions
How do I put an SQL query on one line?
Paste the query, choose your dialect, and click Minify SQL. Line breaks and indentation are removed so the query fits in a compact form.
Will minifying break my query?
It removes whitespace and line breaks and does not change keywords, identifiers, or string values. Check queries that contain comments, because a -- comment affects the rest of its line.
Why do I need to select a dialect?
Dialects differ in how they quote names, which keywords they treat as reserved, and which syntax they allow. Choosing the right one helps the tool read your query correctly.
How are comments handled?
Comments are kept. A -- comment runs to the end of the line, so the minifier keeps the line break after it. Block comments such as /* ... */ stay inline. For a strict one-line query, remove -- comments first.
Are string values preserved?
Yes. Text inside single quotes is never changed, including repeated spaces, and placeholders such as ? are kept as written.
What is the difference between minify and beautify?
Minify compacts SQL into minimal whitespace for embedding in code. Beautify formats SQL with indentation for reading and debugging.
Does minifying SQL improve performance?
No. The database parses the same statement either way. Minifying reduces size in code, logs, and network messages, not execution time.
Is my SQL uploaded to a server?
No. All processing happens in your browser using the sql-formatter library, and your queries never leave your device.