About the SQL Formatter
Break a one-line SQL query from a log or ORM debug output into readable lines, or collapse a formatted query onto one line. Format starts a new line at each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, JOINs, LIMIT, INSERT, UPDATE, DELETE, VALUES, SET) and uppercases those keywords. Input type also offers simple JSON-to-CSV and CSV-to-JSON modes.
How to use the SQL Formatter
- Leave Input type on SQL, or upload a file under Upload file (the type is picked from the file extension).
- Paste your query into SQL input.
- Click Format SQL for one clause per line, or Minify SQL for a single line.
- Copy the result from Formatted SQL or Minified SQL with Copy.
Worked example: formatting a reporting query from a log
Format puts each listed clause on its own line and uppercases it. Words that are not in the list, such as as, on, and, desc and sum, keep their original case, and no indentation is added.
select o.id, c.name, sum(o.total) as revenue from orders o left join customers c on c.id = o.customer_id where o.status = 'paid' and o.created_at >= '2026-01-01' group by o.id, c.name having sum(o.total) > 100 order by revenue desc limit 20SELECT o.id, c.name, sum(o.total) as revenue
FROM orders o
LEFT JOIN customers c on c.id = o.customer_id
WHERE o.status = 'paid' and o.created_at >= '2026-01-01'
GROUP BY o.id, c.name
HAVING sum(o.total) > 100
ORDER BY revenue desc
LIMIT 20Before you paste the output back into your code
- Never minify a query that has -- comments. Minify joins all lines, so SELECT id -- primary key on one line and FROM users on the next become SELECT id -- primary key FROM users WHERE active = 1, and everything after -- is now a comment. Remove line comments or convert them to /* ... */ first.
- Keywords inside string literals are split too. WHERE subject = 'Please update from billing' gets line breaks inside the quoted text, and the words become UPDATE and FROM. Formatting for reading is fine; do not run the formatted version if your literals contain these words.
- Whitespace inside strings is collapsed. Both modes turn any run of spaces, tabs or newlines into one space, including inside quotes.
- The JSON and CSV modes split on every comma and do not handle quoted fields. For CSV with quoted values, delimiters other than commas or a download option, use the CSV to JSON converter.
Why SQL formatting matters
Unformatted SQL is one of the most common sources of debugging friction in backend development. A 20-line query crammed onto one line with inconsistent casing makes it hard to spot a missing JOIN condition, a wrong GROUP BY column, or a subquery that returns multiple rows where one is expected. Proper formatting surfaces structure — each clause on its own line, indented subqueries, aligned column lists.
Code review is faster when SQL is readable. Reviewers can scan the SELECT list for unexpected columns, verify WHERE conditions cover all necessary filters, and check that JOINs use the right join type without running the query. Formatted SQL also pastes cleanly into documentation, tickets, and analytics dashboards.
SQL dialect differences
Most SQL formatting conventions work across dialects (PostgreSQL, MySQL, SQLite, SQL Server, BigQuery, Snowflake), but dialects differ in details. PostgreSQL uses double quotes for identifiers and single quotes for string literals. MySQL uses backticks for identifiers. SQL Server uses brackets ([column_name]). BigQuery uses backticks like MySQL but supports ANSI double quotes with a flag.
Function names and date handling vary significantly: PostgreSQL has NOW() and CURRENT_TIMESTAMP; MySQL has SYSDATE(); SQL Server has GETDATE(). Window functions (OVER(), PARTITION BY, ROW_NUMBER()) are supported in all modern databases but with slightly different syntax in edge cases. The formatter normalizes keyword casing and spacing but preserves dialect-specific identifiers.
Formatting conventions that improve readability
Uppercase reserved words (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, LIMIT) contrast with lowercase table and column names, making the structure scannable. Each major clause starts on a new line. Columns in SELECT lists, JOIN conditions, and GROUP BY are each on their own line with consistent indentation — especially important for queries with 10+ columns.
CTEs (Common Table Expressions) using WITH ... AS (...) are a major readability win for complex queries. Each CTE gets a meaningful name and is formatted as its own indented block. The final SELECT reads cleanly because the intermediate logic has a named reference. Formatting tools that properly indent CTEs save significant manual effort when working with analytical queries.
Subqueries in WHERE and FROM clauses benefit from indentation that shows nesting depth. A subquery that returns one value (scalar subquery) behaves differently from one used in EXISTS — this distinction is clearer when the subquery is properly indented and isolated. The SQL formatter on this page handles standard formatting automatically, leaving you to focus on query logic rather than presentation.
SQL Formatter: frequently asked questions
- Which SQL dialects are supported?
- The formatter handles standard SQL syntax used by MySQL, PostgreSQL, SQL Server, SQLite, and Oracle. Keywords like SELECT, JOIN, WHERE work across all dialects.
- What does SQL formatting do?
- Formatting adds proper line breaks and indentation to make SQL readable. Major clauses such as SELECT, FROM, WHERE and JOIN start on their own line with the keyword in uppercase, which makes long one-line queries readable.
- When should I use minify?
- Minify removes all unnecessary whitespace, creating compact single-line SQL. Useful for reducing query size in logs, configuration files, or embedded SQL strings in code.
- Is my SQL sent to your servers?
- No. Formatting happens entirely in JavaScript in your browser. SQL queries are not uploaded or stored.