SQL is easy to start and hard to read once a query grows: three joins, a subquery and a window function on one line, copied from a log or an ORM, is nobody’s idea of fun.
The SQL formatter lays a query out for reading, with keywords in the case you choose, or minifies it back to one line. It knows the dialects that parse differently, PostgreSQL, MySQL, SQLite, SQL Server, BigQuery and standard SQL, so placeholders like PostgreSQL’s :name and each dialect’s quoting come out right. Formatting changes only whitespace and keyword case, never what the query does.
To learn to write queries rather than tidy them, SQL Detective is a mystery told in fourteen cases, each solved by a query that runs on a real PostgreSQL 18 database inside your browser. It starts with SELECT and WHERE and works through joins, grouping, subqueries and window functions, judging the rows you return against a reference query rather than your wording.
The habit both of them teach is reading a query in the order the database runs it: FROM and the joins first, then WHERE, GROUP BY and HAVING, then SELECT, and ORDER BY last. Most confusing results make sense in that order, like a filter on an aggregate that needs HAVING, or a LEFT JOIN undone by a WHERE on the right-hand table.