How to Format Messy SQL So You Can Actually Read It

By Daniel · Updated July 2026

SQL copied out of application logs or an ORM usually arrives as one enormous line. Formatting it — putting each clause on its own line and indenting the joins — is the fastest way to understand what a query does and to spot the bug you are hunting.

What good formatting shows you

Once SELECT, FROM, each JOIN and the WHERE clause sit on their own lines, the shape of the query becomes obvious: how many tables it touches, which joins might multiply rows, and where a missing condition is causing a runaway result. A tidy layout turns a five-minute squint into a five-second read.

How to format a query

  1. Open the SQL formatter and paste your query.
  2. It re-indents the query with clauses and joins on their own lines.
  3. Copy the clean version back into your editor. Your query never leaves your browser, which matters if it contains table or column names you would rather not share.

Formatting is not optimising

A formatter changes only whitespace and capitalisation — it will not make a slow query fast. But it makes the reasons a query is slow far easier to see, such as a join with no condition or a filter on a column that is not indexed.

SQL Formatter
Paste a query and get clean, indented SQL back — formatted locally in your browser.
Open the tool →

Common questions

Does formatting change what my query does?

No. It only changes spacing and capitalisation. The query runs exactly the same.

Is my SQL sent to a server?

No. It is formatted in your browser, so table and column names stay private.

Which SQL dialects work?

Standard SQL and the common dialects (MySQL, PostgreSQL, SQL Server) all format cleanly.

Can it make my query faster?

Not directly, but a readable query makes performance problems much easier to spot and fix.

Keep reading

How to Format Messy JSON · How to Convert CSV to JSON · How to Convert JSON to CSV