Example: a query against a table of leads
A freelancer has loaded an exported lead list into a small database and written a quick query to count well-rated businesses by town. Typed in a hurry, it is one line in lower case. Formatted with upper case keywords and two-space indent, the structure is easy to check: what is selected, what is filtered and how it is grouped and sorted.
Function names such as COUNT follow the keyword case, while table names, column names and quoted values are left alone.
select name, town, count(*) as leads from businesses where town in ('Leeds','York') and rating >= 4.5 group by name, town order by leads desc limit 20SELECT
name,
town,
COUNT(*) AS leads
FROM businesses
WHERE town IN ('Leeds', 'York')
AND rating >= 4.5
GROUP BY name, town
ORDER BY leads DESC
LIMIT 20Formatting a query
Paste the SQL
One statement or several. The presets offer a join query, an update statement and a subquery if you want to see the formatting first.
Choose keyword case
UPPER CASE is the traditional style and makes keywords stand out. lower case suits some team styles. Keep as typed changes only the layout.
Choose the indent
Two or four spaces for the column list and for extra conditions after WHERE.
Copy or download
Copy the formatted SQL or download it as query.sql to keep with your notes or a report.
Why tidy SQL is worth the click
Most mistakes in a query hide in the WHERE clause: an OR without brackets, a condition on the wrong table after a join, a date compared as text. With each condition on its own line those problems become visible. The same goes for a long SELECT list, where a missing comma can silently turn two columns into one with an alias.
Formatted SQL is also kinder to whoever reads it next. If you share a query with a client, paste it into a spreadsheet's notes or keep it for next month's report, the tidy version will still make sense when you come back to it.
Questions people ask
Which SQL dialects does it support?
The formatter works on the common structure shared by SQLite, MySQL, PostgreSQL and SQL Server: SELECT, joins, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, INSERT, UPDATE and so on. Dialect-specific keywords are passed through as typed. If a particular construct comes out oddly, the query will still run exactly as before, because only whitespace and keyword case change.
Does it change what my query does?
No. It changes line breaks, indentation and, if you ask, the case of keywords. Table names, column names, numbers and anything inside quotes are kept as written, so the database receives the same instructions.
Should SQL keywords be upper case?
It is a convention, not a rule; SQL keywords are not case sensitive. Upper case makes the structure of a query stand out from the names of tables and columns, which is why many style guides use it. Pick one style and keep to it across your queries.
Is my SQL sent to a server?
No. Formatting happens on this page in your browser. That matters when a query contains table names, customer data in a WHERE clause or other details you would rather not paste into an online service.
Where your data goes
Formatting runs in your browser. The SQL you paste, including any values in it, is not sent to Map Extract or anywhere else.
Checked against the tool on