SQL Minifier

Paste a query and the one-line version appears below. Comments go, extra spaces go, and the text inside quotes stays exactly as it was.

How it works

The minifier splits your SQL into tokens: keywords, names, numbers, strings, comments and punctuation. It then writes them back on one line with a single space where a space is needed.

Comments are removed, both -- line comments and /* block */ comments. That matters: if a -- comment stayed when the query became one line, it would comment out everything after it. Optimizer hints written as /*+ ... */ are kept, because they change how the database runs the query.

Spaces before a comma, a closing bracket or a semicolon are removed, and so are spaces after a comma or an opening bracket. Every other space becomes one space, so "a - -1" never becomes "a--1", which would start a comment. Strings and quoted names are copied exactly. The minifier runs on this page, and your SQL is not uploaded.

How to use it

  1. 1 Paste your SQL into the first box.
  2. 2 The one-line query appears in the second box as you type, with the size before and after.
  3. 3 Press Copy result, or download it as a .sql file.

Good to know

  • A one-line query is easy to put in a log line, a CSV cell, a JSON string or a shell command.
  • Use the SQL Formatter to lay the query out again. It cannot bring back the comments, so keep the original if they matter.
  • Line breaks inside a string are part of the string, so a query with a multi-line string literal stays on several lines.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Why joining the lines of a SQL query can break it, and what to remove first

Take a short query written over five lines. Line one is SELECT, then an optimizer hint /*+ INDEX(o idx_total) */, then name, and then a comment, -- who. Line two is total, lined up under name. Line three is FROM orders. Line four is WHERE total > 100, followed by the comment -- big ones. Line five is AND status = 'paid' with a space before the semicolon. With its alignment spaces, the query is 128 characters.

The quick way to get this on one line is to replace each line break with a space. Try it in your head. The first line ends with -- who, and a -- comment runs to the end of its line. After the join, the end of its line is the end of the query. The database now sees SELECT, the hint, name, and nothing more, because everything else is part of the comment. Depending on the database, you get a syntax error or a query that returns the wrong columns. This is the most common way a hand-minified query breaks.

So the minifier removes comments before it joins anything. Both -- who and -- big ones go. The hint does not, because a comment that starts with /*+ is an instruction to the query planner in Oracle and MySQL, and it changes how the query runs. Then the alignment spaces collapse to one space, the space before the semicolon goes, and the space after the comma goes too. The result is SELECT /*+ INDEX(o idx_total) */ name,total FROM orders WHERE total > 100 AND status = 'paid'; at 94 characters, about 27% shorter.

Some spaces cannot go, even where they look spare. In "total > 100", removing the spaces would be safe. In "a - -1", it would not: "a--1" starts a comment. In "SELECT name FROM", removing a space would merge two words. The minifier only removes spaces around commas, brackets and semicolons, where no two tokens can merge, and keeps one space everywhere else. That gives up a few bytes to make sure the query still means the same thing. The string 'paid' is copied as it is, and so is any space or line break inside a string.

Know the limits. The minifier does not check your SQL, so a broken query stays broken. It cannot bring back comments once removed, so keep the readable version if the comments explain anything. And a string that holds a line break keeps that line break, so the output is one line only when the strings in it are one line. For reading a minified query again, the SQL Formatter does the reverse.

Frequently asked questions

Why not just remove the line breaks?

Because a -- comment runs to the end of its line. Join the lines and the comment swallows the rest of the query. The minifier removes comments first, so the one-line query means the same thing as the original.

Are optimizer hints kept?

Yes. A comment that starts with /*+ is a hint in Oracle and MySQL, and in PostgreSQL with the pg_hint_plan extension. It changes the query plan, so the minifier keeps it. Every other comment is removed.

Will it change my strings?

No. Text inside single quotes, double quotes, backticks and square brackets is copied exactly, spaces and line breaks included. So are PostgreSQL dollar-quoted strings.

Does it check that my SQL is correct?

No. It removes comments and whitespace and leaves everything else alone. A query that was wrong before is wrong in the same way after.

Is my SQL sent to a server?

No. The minifier is JavaScript running on this page. Nothing you paste leaves your device.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.