Format SQL

Format SQL with readable clauses, indentation, and nested subqueries.

freeworks offlinenothing uploaded
ToolSQL Formatter
Input
Output

How it works

SQL tokens are re-emitted around SELECT, FROM, JOIN, WHERE, grouping, and nested queries while strings and comments remain intact. Layout changes do not alter query semantics.

  • One clause per line exposes joins and predicates.
  • Keyword casing remains a style choice.

Worked example

Format SELECT Query
Format a complex SQL query with proper indentation and keyword casing
Input
											select u.name, o.total from users u inner join orders o on u.id = o.user_id where o.total > 100 order by o.total desc limit 10
										
Output
												SELECT
  u . name,
  o . total
FROM
  users u
  INNER JOIN orders o
  ON u . id = o . user_id
WHERE
  o . total > 100
ORDER BY
  o . total DESC
LIMIT
  10
											

When to use this

Code reviews, readable migrations, and notebook queries format SQL.

Edge cases

  • Newlines inside strings remain data.
  • Comments can contain SQL-looking punctuation.
  • Nested subqueries need separate indentation scopes.

References