Skip to main content
Screendesk
Free tool

SQL Formatter & Minifier

Beautify SQL with one clause per line and indented subqueries, or minify it to a single line. Strings and comments stay exactly as written.

Open source on GitHub

SQL input

Formatted SQL

Formatted SQL appears here as you type.

Runs entirely in your browser. Nothing you paste here is uploaded or stored.

How it formats

Formatting rules. What changes when you format a query, and what never does.

SQL formatting rules
PartRule
ClausesSELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, INSERT INTO, VALUES, UPDATE, SET, DELETE FROM, and RETURNING each start a new line.
ListsColumns, GROUP BY and ORDER BY items, SET assignments, and VALUES rows go one per line, indented under their clause.
JoinsEvery JOIN variant (INNER, LEFT, RIGHT, FULL, CROSS, NATURAL, with or without OUTER) starts a line with its ON or USING condition.
ConditionsAND and OR in WHERE, HAVING, and ON start a new indented line. The AND inside BETWEEN … AND … stays inline.
SubqueriesA parenthesis followed by SELECT or WITH opens an indented block; function calls and IN lists stay on one line.
Set operatorsUNION, UNION ALL, INTERSECT, and EXCEPT sit on their own line between the two queries.
UntouchedString literals, quoted identifiers ("x", `x`, [x]), dollar-quoted strings, and comments are kept exactly as written.
Reference

Logical order of a SELECT. The order the database evaluates clauses, which explains most alias and aggregate errors.

Logical query processing order
StepWhat happens
1. FROM / JOINPick the source tables and combine them.
2. WHEREFilter rows. Column aliases from SELECT aren’t available yet.
3. GROUP BYCollapse rows into groups.
4. HAVINGFilter groups, usually on aggregates like COUNT(*) > 5.
5. SELECTCompute the output columns and aliases; window functions run here.
6. DISTINCTRemove duplicate rows.
7. ORDER BYSort. Aliases from SELECT can be used here.
8. LIMIT / OFFSETReturn a slice of the sorted rows.
FAQ

Frequently asked questions

How do I format a SQL query?

Paste your query into the input box. It is formatted as you type: keywords are uppercased, each major clause starts on a new line, column lists and conditions are indented, and subqueries get their own indented block. Choose 2 spaces, 4 spaces, or tabs, and whether keywords should be uppercase, lowercase, or left as written.

Which SQL dialects does the formatter support?

It handles standard SQL plus the common syntax of PostgreSQL, MySQL, SQL Server, SQLite, and BigQuery: double-quoted, backtick, and bracketed identifiers, dollar-quoted strings, :: casts, $1, ? and :name placeholders, and --, #, and /* */ comments. It only changes whitespace and keyword case, so dialect-specific syntax passes through unchanged.

What does the SQL minifier do?

Minify removes comments and collapses the query onto one line with only the spaces it needs, which is handy for logging, embedding a query in a string, or comparing two queries. Optimizer hints written as /*+ … */ or /*! … */ are kept.

Will formatting change what my query does?

No. The formatter tokenizes the query so it never edits text inside string literals, quoted identifiers, or comments. Only the whitespace between tokens and the case of keywords and built-in function names change. Quoted identifiers keep their case, so "Order" stays "Order".

Is my SQL sent to a server?

No. Formatting runs entirely in your browser. Your queries, table names, and any values in them are not uploaded or stored.

Customer support runs on Screendesk.

Start for free