Start here
Lessons and reference
Look things up
Start here
SQL
Power Query
Data modeling
Power BI and DAX
Finance playbooks
Run queries
Build and check
Format a SQL Server or MariaDB query, see in plain words what it does, and get a list of common mistakes to check.
Best effort. It reads the formatted query, so unusual syntax can be missed.
Format a query to see its tables, joins, filters, grouping and sorting.
Errors are clear mistakes. Warnings are often wrong or slow. These checks run after formatting.
You write SELECT first, but the database works in a different order. Most "why can't I use my alias here?" errors come from this.
SELECT runs late, so a column alias made there can be used in ORDER BY but not in WHERE.
Pick SQL Server or MariaDB and paste your SQL.
Get a tidy layout and an outline of tables, joins, filters, grouping and sorting.
Common errors and slow patterns are listed with a reason.
The formatter reads your query with a tokenizer that keeps strings, quoted names such as [Order Date] or "Name", comments and brackets whole. A word inside a string, such as 'from where', is never treated as a clause. Keywords and built-in function names are written in capitals.
The layout then puts each major clause on its own line: SELECT, FROM, each JOIN with its ON condition indented under it, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT or TOP. Each select item sits on its own line. AND and OR start a new line inside a WHERE or ON condition. A subquery inside brackets is indented under the line that opens it, and a WITH clause lists each named result as a block.
The outline and the checks read the formatted text back. The outline lists the tables a query reads, each join with its type and condition, the filters, the grouping, the sorting and any row limit. The checks look for common mistakes, listed below.
SELECT * with no list of columns. A JOIN with no ON condition, which becomes a cross join. A comparison with NULL made with an equals sign, which never matches. A WHERE condition on the right-hand table of a LEFT JOIN, which turns the join into an inner join. A function wrapped around a column in WHERE. A number in quotes compared with a column. TOP without ORDER BY, or LIMIT without ORDER BY in MariaDB. LIMIT in SQL Server, or TOP in MariaDB.
A LEFT JOIN keeps the rows of the first table even when there is no match. A condition in WHERE on the second table removes those unmatched rows, so the result is the same as an INNER JOIN. If that is what you want, say INNER JOIN. If not, move the condition into the ON clause.
No. The formatting, the outline and the checks run in your browser.
The SQL editor on this site reads its database from the address, but it does not take a query in the address. Paste the formatted query into the editor to run it.
More tools: all tools · function reference · guides