Making a 400-Line Query Reviewable
By toolbelt maintainers ·
Updated
Long queries rarely have logic bugs. They have formatting bugs — a join that binds to the wrong line and nobody notices in review.
What is this tool?
A SQL formatter lays out a query so clauses and joins are visually separated, which is how you spot a missing condition.
How it works
sql-formatter parses the dialect you pick and re-prints it with aligned keywords and indented subqueries. Dialect matters: MySQL backticks and T-SQL brackets are not interchangeable, and the wrong dialect produces confusing errors rather than helpful ones.
Example
Before: select u.name,count(o.id) from users u left join orders o on o.user_id=u.id group by u.name having count(o.id)>0 order by 2 desc After: select u.name, count(o.id) from users u left join orders o on o.user_id = u.id group by u.name having count(o.id) > 0 order by 2 desc
When to use it
Before code review, always. When a query returns more rows than you expected, formatting usually shows you the missing WHERE clause within seconds.
Optimization Tips
Check that your LEFT JOIN did not become an INNER JOIN because of a condition in the WHERE clause. It is the single most common SQL bug, and it is nearly invisible in unformatted queries.
Frequently Asked Questions
Which dialects are supported?
Does it optimise my query?
Why does the wrong dialect matter?
Does it touch my data?
Related tools
- JSON FormatterBeautify, validate, minify, and view JSON. Format messy API responses into readable code or compress it to save bandwidth, running safely in your browser.
- JSON ValidatorValidate JSON syntax with detailed error messages. Catch trailing commas, missing brackets, and syntax errors instantly before sending payloads to your API.
- JSON MinifierCompress JSON to a single line. Remove all unnecessary whitespace and line breaks to reduce payload size for production APIs without altering the underlying data.
- JSON ViewerView JSON in an interactive, collapsible tree structure. Easily navigate massive API responses, expand specific nodes, and inspect deeply nested objects or arrays.