SQL Formatter
Beautify and format messy SQL queries with proper indentation and keyword highlighting. Free, instant, runs entirely in your browser.
Why Format SQL?
SQL is easy to write as a single unbroken line, but extremely hard to read that way. A query with multiple JOINs, nested subqueries and a long WHERE clause becomes impossible to debug or review when everything runs together. The SQL Formatter breaks your query into a clean, readable structure: each major clause starts on its own line, reserved words are capitalised consistently, and nested blocks are indented. The result is immediately understandable — by you, by teammates in a code review, and by anyone reading your documentation.
Before and After
select u.id, u.name, count(o.id) as orders from users u left join orders o on u.id = o.user_id where u.created_at > '2024-01-01' group by u.id having count(o.id) > 5 order by orders desc limit 20
SELECT u.id, u.name, COUNT(o.id) AS orders FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.created_at > '2024-01-01' GROUP BY u.id HAVING COUNT(o.id) > 5 ORDER BY orders DESC LIMIT 20
SQL Keyword Reference
| Clause | Purpose |
|---|---|
| SELECT | Choose columns to return |
| FROM / JOIN | Specify source tables and how they relate |
| WHERE | Filter rows before grouping |
| GROUP BY | Aggregate rows by a column |
| HAVING | Filter aggregated results (after GROUP BY) |
| ORDER BY | Sort the output (ASC or DESC) |
| LIMIT / OFFSET | Paginate results |
When to Use a SQL Formatter
- Code review — formatted SQL makes JOIN conditions and WHERE logic easy to scan for mistakes.
- Debugging slow queries — structure reveals subquery depth and missing index hints.
- Documentation and README files — readable SQL in docs saves teammates hours of parsing.
- Copying from ORMs or logs — ORM-generated SQL is notoriously compact; formatting makes it human-readable instantly.
All processing happens in your browser — no query text is ever sent to a server, making this safe for queries containing production data or sensitive column names.