Why formatting a query matters
A query copied out of a log or an ORM arrives as one enormous line. Formatted, the same query shows its shape at a glance: what is selected, what it joins, where it filters. Most of the time, finding the bug in a slow or wrong query starts with being able to read it.
What the formatter does
- Puts each major clause — SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY — on its own line
- Indents subqueries and bracketed expressions
- Puts keywords in upper or lower case, consistently
- Keeps comments and string literals exactly as they were
- Minifies back to one line when you need the query in a config value or a shell command
How to use the SQL formatter
- Paste the query — one statement or a whole script.
- Pick your dialect so that quoting and dialect-only keywords are handled properly.
- Copy the result back into your editor, or tick minify to collapse it into one line.
Reading a formatted query
- Count the joins. A query with six joins and a
SELECT *is usually where the slowness lives. - Look at what is in
WHEREbut not in any index — that is the next thing to check withEXPLAIN. HAVINGfilters after grouping andWHEREbefore it. Moving a condition from one to the other changes both the result and the speed.
Privacy
Queries often contain table names, column names and real values. Everything here runs in your browser — the query is never sent to a server, and nothing is logged.
Frequently asked questions
How do I format a SQL query online?
Paste it above and it is formatted as you type. Choose your database dialect so that quoting and dialect-specific keywords are treated correctly.
Does formatting change what the query does?
No. Only whitespace and the case of keywords change. String values, comments and identifiers are left exactly as they were.
Can I put the query back on one line?
Yes — tick "minify instead". Comments are stripped and the whitespace collapsed, which is what you want for a config value or a command line.