SQL Guide
29 short guides covering SQL from scratch — written to be read, not skimmed.
Beginner
Start here. No assumptions. Covers the concepts that show up in every SQL query you will ever write.
How a Database Thinks
What a relational database actually is and why it works the way it does.
Your First SELECT
The anatomy of a SELECT statement and how to start reading data.
Filtering with WHERE
How to ask for only the rows you actually want.
NULL: The Absent Value
Why NULL is not zero, not empty string, and why it breaks the rules you expect.
Sorting and Limiting
ORDER BY, LIMIT, and OFFSET: controlling the shape of your result set.
Aggregation: COUNT, SUM, AVG
Collapsing many rows into a single summary value.
GROUP BY and HAVING
Summarizing data by category, and filtering those summaries.
JOINs: Combining Tables
How to pull related data from multiple tables into a single result.
Subqueries
Queries inside queries: how to use one result as input for another.
String and Date Functions
The most useful built-in functions for working with text and time.
Intermediate
Window functions, CTEs, indexes, and the deeper mechanics of how SQL works.
Window Functions
Aggregations that keep the original rows: ranking, running totals, and more.
CTEs: The WITH Clause
Named temporary result sets that make complex queries readable.
CASE WHEN
Conditional logic inside your SQL: branching without a programming language.
Set Operations: UNION, INTERSECT, EXCEPT
Combining the results of multiple queries as if they were sets.
Self-Joins
Joining a table to itself to find relationships within the same dataset.
Indexes: How Databases Find Data Fast
What indexes are, when they help, and when they do not.
Query Planning and EXPLAIN
How the database decides to run your query, and how to read the plan.
Data Types and Casting
The types that matter most and how to convert between them.
Views
Saved queries that behave like tables: when to use them and when not to.
Constraints and Data Integrity
The rules you teach the database so it can protect your data.
Logical Query Processing Order
The order SQL evaluates your query, which matters more than you think.
Advanced
Recursive queries, transactions, isolation levels, and performance tuning.
Recursive CTEs
Traversing hierarchies and graphs in pure SQL.
Lateral Joins
Subqueries that can see the current row: the tool for top-N per group.
JSON in SQL
Storing and querying semi-structured data with PostgreSQL's JSONB.
Transactions: All or Nothing
How databases guarantee that related changes succeed or fail together.
Isolation Levels
The tradeoff between concurrency and correctness in multi-user databases.
Partitioning
Splitting large tables into smaller pieces for better query performance and data management.
Stored Procedures and Functions
Encapsulating logic in the database: when it makes sense and when it does not.
Performance Tuning
A systematic approach to finding and fixing slow queries.