About the SQL Formatter
Turn long one-line SQL into readable, well-indented queries. Supports MySQL, MariaDB, PostgreSQL, SQL Server, Oracle PL/SQL, SQLite, BigQuery, Snowflake and Redshift.
Key features
- 10 SQL dialects
- Uppercase, lowercase or unchanged keywords
- Clauses, joins and conditions on separate lines
- Formats several statements at once
- Syntax highlighting
- Private: queries stay in your browser
Make long SQL queries readable
Queries copied from logs, ORMs or application code often arrive on a single line. Format them with each clause, join and condition on its own line so you can read, review and debug them.
Before and after
select u.id, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = 1 group by u.id order by orders desc;
becomes
SELECT
u.id,
count(o.id) AS orders
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE
u.active = 1
GROUP BY
u.id
ORDER BY
orders DESC;
Tips for readable SQL
- Use table aliases (
u,o) consistently. - Put each join on its own line with its condition.
- Prefer explicit joins (
LEFT JOIN … ON) over comma joins. - Comment complex conditions with
--.
Related tools
JSON formatter, CSV to JSON, and text diff to compare two queries.
How to use the SQL Formatter
- Paste your code into the input box, upload a file, or click Sample to try it out.
- Choose the options you want, such as indentation, line width or dialect.
- The result appears instantly in the output panel. Syntax errors are shown with their line and column.
- Click Copy to copy the result, or Download to save it as a file.