SQL Formatter
Beautify and format SQL queries with proper indentation
Input SQL
209 charsFormatted SQL
select u.id, u.name, u.email, count(o.id) as order_count from users u left join orders o on u.id = o.user_id where u.active = 1 and u.created_at > '2024-01-01' group by u.id order by order_count desc limit 50;
About the SQL Formatter
This SQL formatter indents a query by clause, aligns joins and conditions and normalises keyword casing, turning a single-line query pulled from a log into something you can actually read and reason about.
A SQL formatter earns its place the moment a query gets complicated. Queries logged by an ORM or copied out of application code arrive as one continuous line, and a five-table join with a couple of subqueries is genuinely unreadable in that form.
Formatting by clause is what makes the logic visible. SELECT, FROM, JOIN, WHERE, GROUP BY and ORDER BY each start a line, join conditions align beneath their join, and subqueries indent as nested blocks — so the shape of the query matches the shape of the thinking behind it.
It also exposes the bugs. A join condition accidentally sitting in the WHERE clause, or an OR that needs bracketing to behave as intended, are hard to spot on one line and obvious once indented. Formatting happens in your browser, so queries containing real table and column names stay local.
How to use the SQL Formatter
- Paste your query. Enter the single-line or messy SQL.
- Format it. Clauses are indented and keywords normalised.
- Read the structure. Follow the joins, conditions and subqueries.
- Copy the result. Take the formatted query.
SQL Formatter features
- Each major clause starts its own line
- Join conditions aligned beneath their join
- Subqueries indented as nested blocks
- Keyword casing normalised
- Copy the formatted query
- Runs in your browser; queries are not uploaded
Frequently asked questions
Why bother formatting SQL?
Because queries logged by an ORM or copied out of application code arrive as one continuous line, and a five-table join with a couple of subqueries is genuinely unreadable that way. Indentation by clause makes the logic visible.
Can formatting help me find a bug?
Often, yes. A join condition that has drifted into the WHERE clause, or an OR that needs bracketing to behave as intended, is nearly invisible on one line and obvious once each clause sits on its own.
Does it check my SQL is valid?
No. It reformats the text according to clause structure and does not parse against a particular dialect, so it will happily lay out a query your database would reject. Run it to find out whether it works.
Does it change what my query does?
No. Only whitespace, line breaks and keyword casing change. The statement is the same statement, which is why it is safe to format one you are about to run.
Is my query uploaded?
No. Formatting happens in your browser, so queries containing real table names, column names or embedded values stay on your machine.