Free No sign-up Client-side

SQL Minifier

Flatten a multi-line query into one clean line — comments removed, indentation collapsed — ready to drop into a string literal or a log.

InputSQL
Output
Input: 0 lines · 0 charsOutput: 0 lines · 0 chars Processed locally in your browser

Why turn a query into one line

SQL is usually written across many lines, with indentation and comments, because that's how it stays readable. But there are moments when you need the opposite: a single tight line you can paste into a string literal in application code, drop into a log line, or hand to a tool that expects one statement per line.

This minifier does exactly that. It removes single-line comments (-- and #), multi-line /* … */ comments, and then collapses every run of whitespace — spaces, tabs, newlines — down to a single space, trimming the ends. The result is the same query, just flattened.

It's a text transformation, not a SQL engine, so it works with any dialect — Postgres, MySQL, SQL Server, SQLite — and runs entirely in your browser. No query ever touches a server.

Flattening a query in four steps

  1. 1

    Paste your SQL

    Add your formatted query to the input pane, or upload a .sql file.

  2. 2

    Get the one-liner

    Comments are stripped and whitespace collapsed, producing a single line on the right.

  3. 3

    Scan the result

    Check the compact query reads correctly before you use it.

  4. 4

    Copy or download

    Take the minified SQL to your clipboard or save it as a .sql file.

Where a one-line query helps

Embedding in code

A single line drops cleanly into a string literal without awkward concatenation across lines.

Cleaner logs

One statement per line keeps query logs grep-friendly and easy to scan.

Stripping stray comments

Internal notes and TODOs in -- and /* */ comments are removed before the query is shared.

Works with any dialect

It's a pure text transform, so Postgres, MySQL, SQL Server and SQLite are all fine.

Before and after

A formatted, commented query on the left; the flattened line on the right.

Formatted → minified
-- active premium customers
SELECT c.id, c.name
FROM customers AS c
JOIN subscriptions AS s
  ON s.customer_id = c.id
WHERE c.active = 1   /* live accounts */
  AND s.plan = 'premium';
SELECT c.id, c.name FROM customers AS c JOIN subscriptions AS s ON s.customer_id = c.id WHERE c.active = 1 AND s.plan = 'premium';

A practical caveat about string literals

Because this minifier works on text rather than understanding SQL grammar, it treats a -- anywhere on a line as the start of a comment and collapses all whitespace uniformly. If your query contains a string literal that includes --, a #, or significant multiple spaces, those will be affected too. For everyday queries this is exactly what you want; for queries with unusual string contents, eyeball the output before relying on it.

What the minifier does

  • Removes -- line comments and # line comments.
  • Removes /* … */ block comments.
  • Collapses tabs, newlines and repeated spaces into a single space.
  • Trims leading and trailing whitespace from the whole statement.

Frequently asked questions

No. It's a text-based minifier, not a SQL parser, so it won't tell you whether the query is syntactically correct or will run. It only strips comments and collapses whitespace.

It can. Because it doesn't parse SQL grammar, a -- , # or run of spaces inside a string literal is treated the same as one in the code. Review the output if your query has unusual string contents.

All of them. Since it's a pure text transformation, it works equally with Postgres, MySQL, SQL Server, SQLite, Oracle and others.

Yes — single-line -- and # comments and multi-line /* */ comments are all removed, which is handy for stripping internal notes before sharing a query.

No. The whole transformation runs in your browser, so queries — including any sensitive table or column names — stay on your machine.

Not from this tool. Minifying discards the original line breaks and comments, so keep your readable source if you'll need it. A SQL formatter can re-indent the structure but can't restore removed comments.

Need another tool?

Browse the full toolbox or dig into the blog for the engineering behind it.

Call UsWhatsApp