Read SQL more easily

SQL formatter

Tidy up a SQL query so it is easier to read, review and share.

Your SQL is processed in this browser. We do not send the content of your queries to AprenderSQL.es.

Input

Shortcut: Ctrl/⌘ + Enter

Output

Your query is formatted locally. If the parser finds an unclosed string, comment or identifier, it keeps the original instead of producing questionable output.

What the formatter preserves

Strings

The content inside single quotes does not change even if it contains words like SELECT or FROM.

Identifiers

It respects identifiers in double quotes, backticks and square brackets.

Comments and operators

It keeps SQL comments and operators such as <=, <>, != or ||.

When it is worth formatting a query

Before investigating an error

A well-indented query lets you see at a glance where each clause starts, which conditions belong to the same block and whether a subquery is closed in the right place. Formatting does not fix the logic, but it reduces visual noise before you debug.

Before sharing SQL

When someone else has to read your query, a consistent structure makes the JOINs, filters and nesting levels visible. It also makes it easier to compare two versions and spot what really changed.

When studying long queries

Separating SELECT, FROM, JOIN, WHERE, GROUP BY and ORDER BY helps connect the written syntax with the logical order explained in the course. This is especially useful when combining aggregates, CTEs or window functions.

Example: from a compact block to a readable query

If you are given a query such as SELECT category_id,COUNT(*) FROM products WHERE stock>0 GROUP BY category_id HAVING COUNT(*)>2 ORDER BY COUNT(*) DESC;, the formatter splits the clauses and applies consistent indentation. That way you can check the row filter first, then the grouping and finally the group filter.

The aim is not to impose a single style. You can choose two or four spaces and decide whether keywords go in upper or lower case. The contents of strings, comments and delimited identifiers are kept as they are, so a visual change never alters real values.

What it does and what it doesn't do

It gives visual structure

It recognises common clauses and blocks to add line breaks and indentation, without sending the query to a server.

It does not validate the query

A query can be perfectly formatted and still have an incorrect column name, a wrong logical condition, or syntax not supported by your engine.

It does not optimise performance

Formatting does not change indexes, cardinalities or execution plans. For performance, you need to look at the real engine, its statistics and its execution plan.

After formatting, you can open the query in the editor to check the result, or in the explainer to go over what each clause does.

Related tools