Formatted SQL appears here — reindent, align, and copy in one click.
What is a SQL formatter?
A SQL formatter takes dense, single-line, or auto-generated SQL and rewrites it with consistent indentation and line breaks. Developers and analysts reach for it when reviewing joins, debugging filters, cleaning up ORM output, sharing queries in tickets or documentation, and stepping through query plans.
Formatting does not change what a query *does* — it changes how easily a human can read it. Once the layout is consistent, the relationship between SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, and ORDER BY becomes much easier to inspect, especially in queries that mix subqueries and CTEs.
SQL has many *dialects* — PostgreSQL, MySQL, SQLite, T-SQL (Microsoft SQL Server), Oracle, and BigQuery all extend the standard with their own syntax. A good formatter understands the dialect you choose so it doesn't break vendor-specific syntax.
What you'll learn while formatting SQL
SQL clauses have specific roles: SELECT chooses columns, FROM chooses tables, WHERE filters rows, GROUP BY aggregates, and ORDER BY sorts.
Readable indentation reveals nested queries, joins, and conditions that are otherwise invisible in a single-line query.
Dialects matter — RETURNING, LIMIT, TOP, and bracketed identifiers ([col] vs "col") are not portable across databases.
How to format a SQL query step by step
1
Paste the query
Drop your SQL into the input box. Single-line, ORM-generated, or partially formatted SQL all work.
2
Pick the dialect
Choose PostgreSQL, MySQL, SQLite, or T-SQL so the formatter respects vendor-specific keywords like LIMIT, TOP, or RETURNING.
3
Configure style
Pick keyword case (uppercase is standard) and indent width (2 or 4 spaces). Most teams pick uppercase keywords + 2-space indent.
4
Read the formatted output
Each clause sits on its own line, joins are aligned, and subqueries are indented. Comments are preserved.
5
Copy back into your project
Paste the formatted query into your migration, ORM raw query, or BI tool. Everything stays in your browser.
SQL clauses quick reference
The clauses you'll see in 95% of SELECT queries, in the order they're processed conceptually. Vendor references: PostgreSQL SELECT, MySQL SELECT.
Clause
Purpose
Example
SELECT
Pick which columns/expressions to return
SELECT id, name
FROM
Pick the source table(s)
FROM users
JOIN ... ON
Combine rows from another table
JOIN orders ON orders.user_id = users.id
WHERE
Filter rows before grouping
WHERE active = true
GROUP BY
Aggregate rows that share values
GROUP BY country
HAVING
Filter aggregated groups
HAVING COUNT(*) > 10
ORDER BY
Sort the result set
ORDER BY created_at DESC
LIMIT / OFFSET
Paginate the result
LIMIT 20 OFFSET 40
WITH ... AS
Common Table Expression (CTE) — name a subquery
WITH active AS (...)
SQL examples to try
Format a simple query
Input
select id,name from users where active=trueorderby created_at desclimit10
Formatted
SELECT id, nameFROM usersWHERE active =trueORDERBY created_at DESCLIMIT10;
Each clause is now on its own line and the column list is indented. Reviewing this query in code review just got 10× easier.
Inspect a join
Input
select u.name,o.total from users u join orders o on o.user_id=u.id where o.total>100
Formatted
SELECT u.name, o.totalFROM users uJOIN orders o ON o.user_id = u.idWHERE o.total >100;
Aliasing tables (users u, orders o) keeps the column list short. The JOIN ... ON line makes the relationship between tables explicit.
Read a nested subquery
Input
select*from users where id in(select user_id from enrollments where course_id=5)
Formatted
SELECT*FROM usersWHERE id IN(SELECT user_idFROM enrollmentsWHERE course_id =5);
Indenting the inner query shows the dependency clearly. Many subqueries can be rewritten as JOINs or CTEs once the structure is visible.
Common SQL formatting mistakes
Assuming formatted SQL is *correct* SQL. Formatting changes layout, not semantics — a clean-looking query can still produce the wrong answer.
Editing a query while formatting and forgetting to re-test the result.
Ignoring the dialect — LIMIT 10 in PostgreSQL, TOP 10 in T-SQL, and FETCH FIRST 10 ROWS ONLY in standard SQL all do the same thing.
SQL Formatter FAQ
Does formatting SQL change the query result?
No. Formatting only changes whitespace and casing. The database parses both versions to the same query plan, so the result rows are identical.
Why format SQL?
Readable SQL is easier to debug, code-review, teach, and maintain — especially when the query has multiple joins, subqueries, CTEs, or window functions.
What is a SQL dialect?
A SQL dialect is a database-specific extension of standard SQL. PostgreSQL, MySQL, SQLite, T-SQL (SQL Server), Oracle, and BigQuery each have unique syntax beyond the SQL standard.
Can a SQL formatter fix broken queries?
A formatter can reveal syntax problems by re-emitting the query in a structured form, but it can't understand your schema or guarantee the query is logically correct.
Should I uppercase SQL keywords?
Most style guides recommend uppercase keywords (SELECT, FROM, WHERE) and lowercase identifiers, because the visual contrast makes the query structure pop. Pick one style and stay consistent.