Pages

Topics

Tools

↑↓navigate↵openescclose
Formatting & Data

SQL Formatter

Format, indent, and minify SQL for PostgreSQL, MySQL, and SQLite with uppercase keywords and one clause per line.

Runs entirely in your browser — nothing you paste is uploaded.

Presets
287 chars
1 statement1 lines inKeywords are upper-cased; strings, comments, and quoted identifiers are left alone.
live
Formatted SQL
299 chars · 14 lines
SELECT
  c.id,
  c.email,
  count(o.id) AS order_count,
  sum(o.total) AS lifetime_value
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.created_at >= '2026-01-01'
  AND o.status <> 'refunded'
GROUP BY c.id,
  c.email
HAVING count(o.id) > 3
ORDER BY lifetime_value DESC
LIMIT 25;

One clause per line, with SELECT lists, GROUP BY, ON CONFLICT, and subqueries indented. PostgreSQL, MySQL, and SQLite keywords are all recognised.

SQL formatting cheat sheet

quick reference
SELECT … FROM … WHERE
The clause order SQL expects. One clause per line is what makes a long query readable in a review or a log.
LEFT JOIN … ON
Keeps every row of the left table and fills NULL for a missing match; INNER JOIN drops unmatched rows instead.
GROUP BY / HAVING
HAVING filters after aggregation, while WHERE filters rows before it, so it cannot use COUNT or SUM results.
WITH name AS (…)
A common table expression. It is inlined by most planners but keeps a long query readable; add RECURSIVE for self-reference.
ON CONFLICT (key) DO UPDATE
PostgreSQL and SQLite upsert. MySQL uses INSERT … ON DUPLICATE KEY UPDATE instead.
LIMIT n OFFSET m
Page through results, but prefer a keyset cursor (WHERE id > last_id) once the offset grows past a few thousand rows.
All SQL guides