The order SQL runs your query
You write SELECT first, but the database reads it nearly last. Knowing the real order explains most "why doesn't this work?" moments, like why a column name made in SELECT can't be used in WHERE.
FROMandJOINpick the tables and match their rows.WHEREkeeps only the rows you want.GROUP BYputs rows into groups.HAVINGkeeps only the groups you want.SELECTworks out the columns (aggregates and window functions too).DISTINCTremoves duplicate rows.ORDER BYsorts, thenLIMITkeeps the first few.
Mistakes this checker catches
Each of these runs without complaint in at least one database and quietly gives the wrong answer, or works today and breaks later.
Comparing with = NULL
Instead of
WHERE breed = NULLwrite
Learn it: Patterns and NULL →WHERE breed IS NULLColumns missing from GROUP BY
Instead of
SELECT species, name, COUNT(*) … GROUP BY specieswrite
Learn it: GROUP BY →The error it causes →SELECT species, COUNT(*) … GROUP BY speciesAggregates in WHERE
Instead of
WHERE COUNT(*) > 3write
Learn it: HAVING →The error it causes →GROUP BY species HAVING COUNT(*) > 3Functions around an indexed column
Instead of
WHERE EXTRACT(YEAR FROM ordered_on) = 2026write
Learn it: Index-friendly filters →WHERE ordered_on >= '2026-01-01' AND ordered_on < '2027-01-01'A WHERE that cancels a LEFT JOIN
Instead of
LEFT JOIN orders o … WHERE o.status = 'paid'write
Learn it: LEFT JOIN →LEFT JOIN orders o ON … AND o.status = 'paid'AND and OR without brackets
Instead of
WHERE a = 1 OR b = 2 AND c = 3write
Learn it: AND, OR and IN →WHERE (a = 1 OR b = 2) AND c = 3Text in double quotes
Instead of
WHERE name = "Bella"write
Learn it: Filter with WHERE →The error it causes →WHERE name = 'Bella'Whole numbers divided
Instead of
COUNT(*) FILTER (…) / COUNT(*)write
Learn it: Active users and growth →100.0 * COUNT(…) / COUNT(*)UPDATE or DELETE without WHERE
Instead of
DELETE FROM petswrite
Learn it: UPDATE and DELETE →DELETE FROM pets WHERE id = 7LIMIT without ORDER BY
Instead of
SELECT * FROM pets LIMIT 3write
Learn it: Sort and limit →SELECT * FROM pets ORDER BY age LIMIT 3
Why format SQL at all?
One clause per line, keywords in capitals and indented column lists make a query easy to scan: you can see at a glance what's filtered, grouped and sorted, and a missing condition stands out. Formatted SQL also makes code reviews and diffs far easier to read.
Frequently asked questions
- Is my SQL sent to a server?
- No. Formatting and explaining both happen in your browser. Nothing you paste here is uploaded or stored.
- Which SQL dialects does it format?
- PostgreSQL and SQLite, the two databases sqlstreak teaches. Standard SQL from MySQL, SQL Server or BigQuery usually formats fine too, apart from their special syntax.
- How does the explainer work?
- It splits your query into its clauses (WITH, SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT) and describes each one in plain words, then lists the order the database actually works through them. It reads the SQL; it doesn't run it.
- Can it find every bug?
- No. It catches common mistakes that are visible in the SQL itself. It can't know your tables, so it can't tell whether a column exists or a result is what you meant. Run the query to be sure.
Got a CSV export to dig into? Try Query a CSV with SQL.