SQL and PostgreSQL Guide: From First Query to Production
SQL is the one skill that pays off in almost every developer job. This guide follows the SQL series from the first SELECT through joins, grouping and window functions, then adds the production topics: schema design, indexes, transactions and migrations.
Every query in the series was run on a real PostgreSQL server, and the output shown is real.
Who it is for: Beginners learning SQL, and developers who want to understand indexes, transactions and query plans.
15 lessons · Published by Jainik · Last updated
1. The basics
- 1. SQL & PostgreSQL · 18 minTables, SELECT and WHERE
What a relational database is, running PostgreSQL, a small shop schema, SELECT, WHERE, NULL logic, and INSERT, UPDATE and DELETE with RETURNING.
- 2. SQL & PostgreSQL · 18 minJoins: Combining Tables
Primary and foreign keys, inner, left, right, full and cross joins with drawn result tables, self joins and the NULL trap in left joins.
- 3. SQL & PostgreSQL · 20 minAggregates, GROUP BY and HAVING
COUNT, SUM and AVG, GROUP BY rules, HAVING versus WHERE, FILTER, date_trunc reports and the order a SELECT is evaluated.
- 4. SQL & PostgreSQL · 22 minSubqueries, CTEs and Window Functions
Scalar, IN and EXISTS subqueries, WITH queries, a recursive category tree, ranking, LAG and LEAD, running totals and top-N per group.
2. Design and speed
- 5. SQL & PostgreSQL · 22 minDesigning a Schema: Keys, Normalisation and Constraints
Identity versus UUID keys, normal forms with a flat-to-normalised redesign, ON DELETE, enums, money, timestamptz and soft deletes.
- 6. SQL & PostgreSQL · 24 minIndexes and EXPLAIN
How a B-tree helps, composite, covering and partial indexes, and reading real EXPLAIN ANALYZE plans on a million rows.
- 7. System Design · 12 minDatabase Indexing: B-Trees and LSM-Trees
Why an index turns 812 ms into 0.09 ms, and why it slows every write. How B-trees keep sorted pages updated in place, how LSM-trees append and compact for huge write rates, and how to design indexes from real queries.
- 8. System Design · 7 minNormalization vs Denormalization
Store each fact once and writes stay correct; copy facts on purpose and reads get fast. Normal forms in plain English, the anomalies they prevent, the denormalisation toolkit, and how to keep copies in sync.
3. Correctness and production
- 9. SQL & PostgreSQL · 22 minTransactions, Isolation Levels and Locks
Atomicity, read committed versus repeatable read versus serializable with two real sessions, row locks, SKIP LOCKED, deadlocks and retries.
- 10. SQL & PostgreSQL · 24 minPostgreSQL Features: JSONB, Full-Text Search, Arrays and Safe Migrations
JSONB with GIN indexes, full-text search, arrays, upserts, and expand-and-contract migrations that do not lock a busy table.
- 11. System Design · 12 minACID Transactions & Isolation Levels
Two people book the last seat; a transfer crashes halfway. What ACID really promises, the write-ahead log behind durability, the five anomalies isolation levels do (and don't) prevent, and the practical fixes for real race conditions.
- 12. Backend in Depth · 20 minDatabase Fundamentals for API Engineers: Indexes, Transactions, Isolation
B-tree indexes, reading EXPLAIN ANALYZE, transactions and isolation levels, and the race conditions they stop, like selling too many items.
4. Interview questions and deeper Postgres
- 13. Full-Stack Questions · 30 minPrisma & SQL Interview Questions
Prisma 7, migrations, relations, transactions, N+1, raw queries, and the SQL behind it.
- 14. Full-Stack Questions · 41 minSEO, i18n, PWA and PostgreSQL Deeper
Next.js metadata and sitemaps, locale routing and plurals, service workers, window functions, JSONB, EXPLAIN, locks, vacuum and PgBouncer.
- 15. System Design · 12 minSQL vs NoSQL: Picking the Right Data Model
“SQL or NoSQL?” is the wrong question; the right one is “what shape is my data, and how will I read and write it?” The relational model and the four NoSQL families — key-value, document, wide-column and graph — what each is good at, the myths to drop, and a sensible default.
More reading orders are on the guides page, and every series is listed on the home page.