Worked example
A one-line query copied from a log, select id, email from users where status = 'active' and created_at > '2026-01-01' order by created_at desc limit 50, comes out as:
SELECT id, email FROM users WHERE status = 'active' AND created_at > '2026-01-01' ORDER BY created_at DESC LIMIT 50
Each clause starts a line, every selected column has its own line and each extra condition sits under WHERE, so a missing condition or a wrong column is easy to spot in a code review.
A readable SQL style
- One clause per line: SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT.
- Put join conditions on an indented ON line, and AND/OR at the start of each condition line.
- Upper-case keywords and lower-case names is the most common convention; pick one and stick to it.
- Give tables short aliases (u for users) and always qualify columns when joining.
- Indent subqueries and consider turning repeated ones into a WITH (CTE) block.
What a simple formatter can’t do
This formatter works from the shape of the text, not a full grammar for each database, so it is fast and forgiving with unfinished queries, but it won’t catch syntax errors, missing commas or unknown columns. Run the query in your database (or EXPLAIN it) to check it. Very unusual syntax, such as MySQL’s DELIMITER commands or Oracle’s q'[ ]' quotes, may not be laid out ideally.
Formatting in reviews and tickets
Long queries pasted into a ticket, chat or pull request are much easier to review once each clause and column has its own line, because a change then shows up as a one-line difference. Keep the original query alongside if exact spacing matters, for instance in a stored view whose definition is compared byte for byte. For queries that are built in code, format the final SQL your program logs, not the code that builds it, to see exactly what the database ran.
Related tools
- URL encode and decode
- Colour converter
- XML formatter and validator
- CSS gradient generator
- Box shadow generator
- HTML and CSS minifier
- Meta tag analyzer
- Colour palette generator
- Contrast checker
- JSON to CSV
Sources
Checked on November 26, 2026:
- PostgreSQL: Lexical structure (identifiers, strings, comments)
- MySQL 8.4: Schema object names (backtick quoting)
- SQL Style Guide by Simon Holywell
Frequently asked questions
Which SQL dialects does it support?
Will formatting change what my query does?
Can it format stored procedures?
Why are some words not upper-cased?
What does “One line” do?
Is my SQL sent to a server?
Last updated: 2026-11-26