What SQL really is, the relational model, and how to think in sets instead of loops.
Before the tricks, the mental model. SQL is a declarative language built on relations — collections of objects that share a definition. Get these foundations right and everything else clicks into place.
There's no secret sauce — learn the two foundations (relations and declarative thinking), then practice in small steps and build from there.
A table is a relation with storage. Every SQL query you write defines a new relation, assembled on the fly from relations that already exist.
PostgreSQL is not just storage — it is a concurrent data-access service. Here is what that means, and why the PostgreSQL project specifically is the right choice for any serious application.
GROUP BY compresses many rows into one per group. Understanding the evaluation order — WHERE, then GROUP BY, then HAVING, then SELECT — is what makes aggregation queries predictable.
Storing the same fact in more than one place is the root cause of three predictable failures. Understanding update, insertion, and deletion anomalies is what makes normalization feel obvious rather than arbitrary.
NULL is not zero, not an empty string, not false. It means unknown — and that single word explains every surprising thing SQL does with it, from WHERE conditions that silently drop rows to comparisons that never return true.
The most common AI SQL mistake: a LEFT JOIN paired with a WHERE clause that filters on the right-side table, silently turning an outer join into an inner join and dropping the rows you asked for.
After a JOIN, COUNT(*) counts the rows in the intermediate result — which is not the same as counting the distinct entities you care about. The wrong number is plausible, which makes it dangerous.
AI tools default to TEXT columns and application logic because they do not know what your database can express. Knowing PostgreSQL's range types, exclusion constraints, and generated columns changes what you ask for — and what you get.
Go deeper
These lessons are the foundation. The book gives you the complete treatment, with real datasets you can run and the production patterns that turn thousands of lines of code into simple queries.
Get the Book — $89