Skip to content
ErgaLab
SQL

SQL Formatter

Paste a query in any style — one line, inconsistent casing, no indentation — and get it reformatted with clauses, joins, and conditions clearly separated.

Paste your SQL

Formatted output

SELECT o.id,
  c.name,
  o.total
FROM orders o
INNER JOIN customers c ON o.customer_id = c.id
WHERE o.status = 'paid'
  AND o.total > 100
ORDER BY o.created_at DESC
LIMIT 20

How it works

The formatter tokenizes your query and re-indents it around well-known clause boundaries: SELECT, FROM, WHERE, JOIN variants, GROUP BY, ORDER BY, and more. Keywords are uppercased, column lists are broken one-per-line, and AND/OR conditions inside WHERE get their own indented line — except the AND that belongs to a BETWEEN range, which stays inline.

This is a lightweight, dependency-free formatter rather than a full SQL parser, so extremely complex nested subqueries may not reformat perfectly — but the vast majority of everyday queries come out clean. Prefer a more compact, single-purpose framing of the same tool? See the SQL Beautifier.

Examples

One-line query

Before: a single dense line.

select id, name from users where active = true

Same query, formatted

After: clauses separated, keywords uppercased.

SELECT id,
  name
FROM users
WHERE active = true

Frequently asked questions