SQL::DOCS
โŒ‚
The Relational Query Language

SQL Complete Guide

SQL (Structured Query Language) is the standard query language behind every relational database โ€” PostgreSQL, MySQL, SQL Server, and SQLite all speak the same fundamentals underneath their own extensions. Learn to select, filter, sort, join, and aggregate rows once, and that knowledge transfers almost unchanged to whichever engine you end up running in production. This doc walks through the 10 concepts a beginner actually needs, in the order you're likely to need them, with a diagram, a "where to use it" guide, and concrete implementation steps โ€” including runnable SQL snippets โ€” for every single one.

10 topics 10 diagrams 10 SQL snippets 1 language, every major engine

Use the sidebar to jump straight to any topic โ€” each one opens its own page with a full explanation, a diagram of exactly how it fits together, and the concrete steps to actually write it. If you're starting from zero, work through the topics in order: nothing past Joins makes much sense without SELECT & WHERE already comfortable.

Diagram ยท What Happens When You Run a Query
Query raw SQL text Query Planner chooses execution plan Storage Engine executes the plan Result Set rows returned ON-DISK / IN-MEMORY DATA Tables Indexes

Every query follows the same path: the text you write is parsed and handed to the query planner, which decides the fastest way to satisfy it (a full scan, or an index lookup); the storage engine then actually reads the tables (and any indexes) on disk or in memory, and hands back a result set โ€” the rows your application actually sees.

All 10 topics in this guide

Summary & Patterns

Once the individual topics make sense on their own, these two references tie them together: the order to learn them in, and the single most important thing to internalize about how SQL is actually executed.

Recommended Learning Order

Anatomy of a SELECT Statement โ€” Written Order vs. Execution Order

This is the single most useful thing to internalize about SQL: the order you type the clauses is not the order the database evaluates them in.

Diagram ยท Logical Query Processing Order
EVALUATION ORDER โ†’ 1 FROM source table(s) 2 WHERE filters rows 3 GROUP BY buckets rows 4 HAVING filters groups 5 SELECT picks columns 6 ORDER BY sorts result 7 LIMIT caps rows

You write SELECT ... FROM ... WHERE ... GROUP BY ... HAVING ... ORDER BY ... LIMIT, but the engine runs it starting from FROM and finishing near the end with the column list in SELECT โ€” which is exactly why a column alias defined in SELECT can be used in ORDER BY (evaluated after) but not in WHERE (evaluated before SELECT has run at all).

Official Documentation Reference URLs

Every topic covered in this guide, with a direct link to its official docs.