Skip to main content
~/makemydev/sql-formatter

$sql-formatter

Formatters

Paste a query and get a clean, consistently-indented version. Supports SELECT, INSERT, UPDATE, DELETE, CREATE, CTEs, window functions, and multi-statement scripts. Runs entirely in your browser.

SELECT
  u.id,
  u.name,
  count(o.id) AS order_count
FROM users u
LEFT JOIN orders o
  ON o.user_id = u.id
  AND o.status = 'paid'
WHERE u.country = 'US'
  AND u.created_at > '2024-01-01'
GROUP BY
  u.id,
  u.name
HAVING count(o.id) > 0
ORDER BY
  order_count DESC
LIMIT 50;
Options

How to format and minify SQL

Paste any SQL into the input panel and pick Format for a pretty-printed version or Minify to strip whitespace and comments. The formatter understands the common statement shapes — SELECT / INSERT / UPDATE / DELETE / CREATE, CTEs, window functions, subqueries, and CASE expressions — and lays them out with the structure that makes code reviews easy to scan. Every byte stays in your browser.

  1. Paste your query. Multi-statement scripts are fine — the counter in the header tells you how many statements the formatter detected.
  2. Pick a case style. Upper-case keywords are the classic convention and make reviews easier; lower-case fits a modern prose style; preserve leaves your keywords as-typed.
  3. Pick indent & commas. 2 spaces is the default; 4 spaces matches most team style guides; tabs work in editors with configurable tab widths. Leading commas (, col) help spot missing items in long SELECT lists.
  4. Copy, save, or minify. The formatted query is available for copy, download, or you can flip to Minify when you need a one-liner for a tool that does not cope well with line breaks.

What the formatter handles

  • Major clauses on their own line — SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, and the JOIN family all start a new line at the current statement indent.
  • Column lists vertical — items after SELECT, GROUP BY, ORDER BY, SET, and RETURNING break across lines so diffs show one logical change per row.
  • JOIN ... ON nested — the ON predicate sits one level deeper than the JOIN line so it is clearly associated with that table.
  • AND / OR wrapped at clause indent — each new boolean term in a WHERE or HAVING breaks to its own line aligned with the clause body, so complex conditions are easy to follow.
  • CASE expressions expanded — CASE, WHEN, ELSE, and END line up vertically so branches are obvious at a glance.
  • CTEs and subqueries indented — WITH bodies and parenthesized SELECTs open on their own block with the inner statement indented one level deeper.
  • Postgres, MySQL, and SQL Server identifier quoting — double quotes, backticks, and square brackets are preserved as-is.

When to reach for the minifier

Minify strips comments and every non-essential character so the query fits on one line. That is the right form when you need to paste into a JSON field, an environment variable, a log message, or a URL query string. For readable source control, always prefer the formatted version.

Limitations

This is a pretty-printer, not a parser — it does not execute the query, validate columns, or reject invalid syntax. Vendor-specific DDL (stored-procedure bodies, PL/pgSQL blocks, T-SQL BEGIN…END blocks) will be preserved token-for-token but may not be re-indented beyond the surrounding statement. Always diff the formatted output against the original before committing.