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. 1. SQL & PostgreSQL · 18 min
    Tables, 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. 2. SQL & PostgreSQL · 18 min
    Joins: 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. 3. SQL & PostgreSQL · 20 min
    Aggregates, 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. 4. SQL & PostgreSQL · 22 min
    Subqueries, 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

  1. 5. SQL & PostgreSQL · 22 min
    Designing 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.

  2. 6. SQL & PostgreSQL · 24 min
    Indexes and EXPLAIN

    How a B-tree helps, composite, covering and partial indexes, and reading real EXPLAIN ANALYZE plans on a million rows.

  3. 7. System Design · 12 min
    Database 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.

  4. 8. System Design · 7 min
    Normalization 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

  1. 9. SQL & PostgreSQL · 22 min
    Transactions, Isolation Levels and Locks

    Atomicity, read committed versus repeatable read versus serializable with two real sessions, row locks, SKIP LOCKED, deadlocks and retries.

  2. 10. SQL & PostgreSQL · 24 min
    PostgreSQL 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.

  3. 11. System Design · 12 min
    ACID 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.

  4. 12. Backend in Depth · 20 min
    Database 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

  1. 13. Full-Stack Questions · 30 min
    Prisma & SQL Interview Questions

    Prisma 7, migrations, relations, transactions, N+1, raw queries, and the SQL behind it.

  2. 14. Full-Stack Questions · 41 min
    SEO, i18n, PWA and PostgreSQL Deeper

    Next.js metadata and sitemaps, locale routing and plurals, service workers, window functions, JSONB, EXPLAIN, locks, vacuum and PgBouncer.

  3. 15. System Design · 12 min
    SQL 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.