SQL โ€” Database Query Fundamentals

Status: Active Last Updated: 2026-08-29 Category: Databases & Storage Prerequisites: kb/basics/ โ€” Linux fundamentals, command-line basics Tags: sql, sqlite, postgres, mysql, database, queries, joins, indexes

Summary

SQL fundamentals for anyone who will touch a database โ€” from writing basic queries to understanding indexing, joins, and schema design. This stack uses SQLite in development (via Prisma) and PostgreSQL in production. Both are covered.

๐ŸŽฏ Learning Philosophy

SQL is Universal:

Every backend stores data
Every data layer queries with SQL (or an abstraction over it)
Learn SQL once โ†’ use it in SQLite, Postgres, MySQL, beyond

๐Ÿ“š Learning Path

Prerequisites: kb/basics/
         โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  PHASE 1: SQL Fundamentals             โ”‚
โ”‚  โ”œโ”€ SELECT, WHERE, ORDER BY             โ”‚
โ”‚  โ”œโ”€ Filtering, comparison operators     โ”‚
โ”‚  โ”œโ”€ DISTINCT, LIMIT, OFFSET            โ”‚
โ”‚  โ””โ”€ NULL handling (IS NULL, COALESCE)  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  PHASE 2: Joins & Relations            โ”‚
โ”‚  โ”œโ”€ PRIMARY KEY, FOREIGN KEY           โ”‚
โ”‚  โ”œโ”€ INNER JOIN, LEFT JOIN               โ”‚
โ”‚  โ”œโ”€ Self joins, multiple joins          โ”‚
โ”‚  โ””โ”€ UNION, INTERSECT, EXCEPT           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  PHASE 3: Aggregation & Grouping        โ”‚
โ”‚  โ”œโ”€ COUNT, SUM, AVG, MIN, MAX          โ”‚
โ”‚  โ”œโ”€ GROUP BY, HAVING                   โ”‚
โ”‚  โ”œโ”€ Subqueries                         โ”‚
โ”‚  โ””โ”€ Window functions                   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  PHASE 4: Schema & Indexing             โ”‚
โ”‚  โ”œโ”€ CREATE TABLE, ALTER TABLE           โ”‚
โ”‚  โ”œโ”€ Data types and constraints          โ”‚
โ”‚  โ”œโ”€ Indexes (B-tree, GIN, partial)     โ”‚
โ”‚  โ””โ”€ EXPLAIN and query plans            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  PHASE 5: Transactions & Advanced       โ”‚
โ”‚  โ”œโ”€ ACID properties                    โ”‚
โ”‚  โ”œโ”€ BEGIN, COMMIT, ROLLBACK             โ”‚
โ”‚  โ”œโ”€ Stored procedures and functions     โ”‚
โ”‚  โ””โ”€ Migrations and schema versioning    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“– Articles in This Directory

๐ŸŸข Phase 1: SQL Fundamentals

  1. sql-fundamentals โ€” Writing your first queries
    • SELECT, FROM, WHERE
    • ORDER BY, LIMIT, OFFSET
    • Comparison and logical operators
    • NULL handling and COALESCE
    • Prerequisites: None
    • Time: 2-3 hours

๐ŸŸก Phase 2: Joins & Relations

  1. sql-joins โ€” Relating tables together
    • PRIMARY KEY, FOREIGN KEY concepts
    • INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN
    • Multiple joins, self-joins
    • UNION, INTERSECT, EXCEPT
    • Prerequisites: SQL fundamentals
    • Time: 2-3 hours

๐ŸŸก Phase 3: Aggregation & Grouping

  1. sql-aggregation โ€” Summarizing data
    • COUNT, SUM, AVG, MIN, MAX
    • GROUP BY, HAVING
    • Subqueries in SELECT, WHERE, FROM
    • Window functions (ROW_NUMBER, RANK, LAG, LEAD)
    • Prerequisites: Joins and relations
    • Time: 2-3 hours

๐ŸŸ  Phase 4: Schema & Indexing

  1. sql-schema โ€” Designing tables and indexes
    • CREATE TABLE, ALTER TABLE, DROP TABLE
    • Data types: INTEGER, TEXT, REAL, BLOB, SERIAL
    • Constraints: NOT NULL, UNIQUE, CHECK, DEFAULT
    • Indexes: single-column, composite, B-tree, GIN
    • EXPLAIN and reading query plans
    • Prerequisites: SQL fundamentals
    • Time: 3-4 hours

๐Ÿ”ด Phase 5: Transactions & Advanced

  1. sql-transactions โ€” Multi-statement operations
    • ACID: Atomicity, Consistency, Isolation, Durability
    • BEGIN, COMMIT, ROLLBACK
    • Isolation levels (READ COMMITTED, SERIALIZABLE)
    • Migrations: Prisma migrations, raw SQL migrations
    • Prerequisites: Schema design
    • Time: 2-3 hours

๐Ÿ”— What Comes Next?

๐Ÿ“ Change Log

2026-08-29

Choose Theme

Your selection is saved locally.

Neural Cacophony
Aperture v2
Flux v1
Mosaic Chaos
Nexus v1
Nexus Zest
Prism v2
Synapse