SQL Formatter

Paste a query and a readable version appears below. Each clause starts a line, each column gets its own line, and joins keep their ON condition beside them.

How it works

The formatter splits your SQL into tokens: keywords, names, numbers, strings, comments and punctuation. It then writes the query back with SELECT, FROM, WHERE, GROUP BY and the other clauses each starting a new line.

The columns in a SELECT list and the conditions joined by AND or OR each get their own indented line. A JOIN stays on one line with its ON condition. A subquery in brackets is laid out like a query of its own, one level deeper. A function call or an IN list stays on one line.

Strings, quoted names ("x", `x` and [x]) and comments are copied exactly. You can write keywords in capitals, in lower case, or leave them as you typed them. The formatter runs on this page, and your query is not uploaded.

How to use it

  1. 1 Pick how keywords should look: SELECT, select, or as you typed them.
  2. 2 Paste your SQL into the first box. The formatted query appears in the second box as you type.
  3. 3 Press Copy result, or download it as a .sql file.

Good to know

  • Paste several statements at once. Each one ends at its semicolon, and a blank line separates them.
  • Formatting a long query before you debug it makes a missing join condition or a stray OR much easier to spot.
  • PostgreSQL dollar-quoted strings and :: casts are read correctly, so their content is left alone.

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.

Reading a one-line report query by laying it out clause by clause

Here is a query as it often arrives, copied from a log or an ORM: select c.name, count(o.id) as orders from customers c left join orders o on o.customer_id = c.id where c.country = 'NO' and o.total > 100 group by c.name order by orders desc. It is one line of 174 characters. It is valid SQL, but finding the join condition or the filter means reading it from the start every time.

The formatter puts each clause on its own line, with what belongs to the clause indented below it. SELECT is followed by two lines, c.name and COUNT(o.id) AS orders, one column each. FROM is followed by customers c, and on the next line LEFT JOIN orders o ON o.customer_id = c.id. The join keeps its ON condition on the same line, because a join without its condition is hard to read. WHERE is followed by c.country = 'NO', and then AND o.total > 100 on a line of its own. GROUP BY c.name and ORDER BY orders DESC finish the query. The result is 13 short lines.

Now the query is easy to check. You can see there is one join and what it joins on. You can see both filters, and you might notice something worth asking about. The filter o.total > 100 is in the WHERE clause, but o comes from a LEFT JOIN. A customer with no orders has a NULL total, the filter drops them, and the LEFT JOIN acts like an inner join. On one line that is easy to miss. In the formatted query, the LEFT JOIN line and the AND line sit close together.

Notice what did not change. The string 'NO' is still 'NO', in capitals and in quotes. The keywords were turned into capitals because the Keywords option was set to SELECT. Set it to select and they all come out in lower case, or pick As typed and they stay as you wrote them. Common function names such as COUNT, SUM and COALESCE follow the same setting. The alias orders and the table names are not keywords, so they are never changed.

The formatter has limits. It does not parse SQL the way your database does, so it cannot tell you about a missing comma, a wrong column name or a keyword your dialect lacks. It lays out what is there. Very unusual syntax, such as a vendor-specific clause it does not know, still comes out readable but may sit on the line of the clause before it. And it does not change the query in any way: it never reorders clauses, adds aliases or rewrites joins. If the formatted query looks wrong, the original was wrong in the same way.

Frequently asked questions

Which SQL dialects does it support?

It works on the shared shape of SQL, so it handles queries for PostgreSQL, MySQL, SQLite, SQL Server and Oracle. It knows PostgreSQL dollar quoting and :: casts. It does not check the query against any one dialect, so it will lay out SQL your database would reject.

Does it check that my SQL is correct?

No. It lays out the words you give it and does not run or parse the query the way a database does. A misspelled table name or a missing comma comes out formatted, not flagged.

Will it change my strings or comments?

No. Text in quotes, quoted names such as "Order Date" and comments are copied exactly. Keyword case only applies to SQL keywords, never to text inside quotes.

Why is my IN list on one line?

A list of values, a function call and a VALUES row are short and read best on one line. Only a bracket that holds a subquery is broken over several lines.

Is my SQL sent to a server?

No. The formatter 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.