Home / Developer tools / SQL beautifier

SQL Beautifier

Turn a messy, minified or one-line query into readable SQL. Paste it from a log, an ORM or a code string and see the structure of the query at once.

Try:

Everything runs in your browser. Your SQL is not sent to our server.

When you need a SQL beautifier

Queries often reach you in their worst form. You may copy them from:

  • the slow query log or the general log of MySQL, or pg_stat_statements in PostgreSQL,
  • the query log of an ORM, such as Laravel, Hibernate, Django or Entity Framework, where the SQL is one long line,
  • a string in code, where the query was joined from pieces,
  • a monitoring tool or an error report that prints the SQL without line breaks,
  • a minified file, or an export from a database tool.

The beautifier adds the line breaks and the indentation that these sources remove, so that you can see which tables are joined, which conditions filter the rows and how the result is grouped and sorted.

Example

with recent as (select user_id, total from orders where created_at >= '2026-01-01') select u.name, case when sum(r.total)>1000 then 'vip' else 'regular' end as tier from users u join recent r on r.user_id=u.id group by u.name;

becomes:

WITH recent AS (
  SELECT
    user_id,
    total
  FROM orders
  WHERE created_at >= '2026-01-01'
)
SELECT
  u.name,
  CASE
    WHEN SUM(r.total) > 1000 THEN 'vip'
    ELSE 'regular'
  END AS tier
FROM users u
JOIN recent r
  ON r.user_id = u.id
GROUP BY u.name;

How to read a long query

  1. Beautify it first, so that each clause has its own line.
  2. Start at FROM and the JOIN lines to see which tables are used and how they connect.
  3. Read WHERE to see which rows are kept, then GROUP BY and HAVING to see how they are combined.
  4. Last, read the SELECT list to see what is returned, and ORDER BY and LIMIT for the order and the size of the result.

This is also the order in which the database logically works through a query, which is different from the order in which the clauses are written.

Beautifier or formatter?

They are the same thing with different names. This page is set up for the common case of an unreadable query, and the SQL formatter page has the same options and is meant for tidying queries that you write yourself. Both keep the meaning of the query and change only the layout.

Options

Choose the dialect (MySQL, PostgreSQL, SQL Server, SQLite, Oracle or Standard SQL), the indent (two spaces, four spaces or a tab), the keyword case, the comma position and whether AND / OR and CASE use several lines. Table names, column names, aliases and strings are never changed.

Check the result

If the result looks strange, the query itself usually has a problem, such as an unclosed quote or a missing parenthesis. The tool shows a warning for these. Queries copied from logs may also contain placeholders such as ?, $1 or :name. They are kept as they are.

See also the SQL minifier for the reverse, SQL pretty print for line numbers and colors, and the SQL formatting guide.

Frequently asked questions

How do I beautify a one-line SQL query?

Paste the query. The tool adds line breaks and indentation at once, with each clause on its own line.

Can I beautify SQL copied from a log or an ORM?

Yes. Placeholders such as ?, $1 and :name are kept as they are. Choose the dialect of your database for the best result.

What is the difference between a SQL beautifier and a formatter?

There is no real difference. Both change the layout of a query and keep its meaning.

Does it fix errors in my SQL?

No. It does not fix or check the logic. It warns about unclosed strings, comments and parentheses.