SQL, one concept at a time.
Understand the query. Read the result. Know why it works.
All CoreTrail subjects
A practical path from your first SELECT to window frames, query plans, and database design.
Short lessons, worked examples, and the edge cases that make interview answers reliable.
Choose a learning path
Build query fluency
flowchart LR
accTitle: Build query fluency
A["Foundations"] --> B["Filtering"] --> C["Joins"] --> D["Aggregation"] --> E["Subqueries"] --> F["Windows"]
click A href "/coretrail/sql/foundations/overview/" "Open Foundations" _self
click B href "/coretrail/sql/filtering/overview/" "Open Filtering" _self
click C href "/coretrail/sql/joins/overview/" "Open Joins" _self
click D href "/coretrail/sql/aggregation/overview/" "Open Aggregation" _self
click E href "/coretrail/sql/subqueries/overview/" "Open Subqueries" _self
click F href "/coretrail/sql/windows/overview/" "Open Windows" _self
Prepare for interviews
flowchart LR
accTitle: Prepare for interviews
A["Revision maps"] --> B["Worked patterns"] --> C["Mixed drills"] --> D["Explain edge cases aloud"]
click A href "/coretrail/sql/practice/pattern-map/" "Open Revision maps" _self
click B href "/coretrail/sql/patterns/overview/" "Open Worked patterns" _self
click C href "/coretrail/sql/practice/mixed-drills/" "Open Mixed drills" _self
Investigate performance
flowchart LR
accTitle: Investigate performance
A["Diagnosis workflow"] --> B["Plans and indexes"] --> C["Native labs"] --> D["Storage and scaling"]
click A href "/coretrail/sql/performance/workflow/" "Open Diagnosis workflow" _self
click B href "/coretrail/sql/performance/explain/" "Open Plans and indexes" _self
click C href "/coretrail/sql/performance/index-lab/" "Open Native labs" _self
click D href "/coretrail/sql/scaling/overview/" "Open Storage and scaling" _self
Explore the chapters
01
Foundations
Understand tables, keys, data types, and how a query is evaluated.
6 topics 02
Filtering & expressions
Select the right rows and reason carefully about missing values.
2 topics 03
Functions & dates
Transform strings, numbers, dates, and timestamps.
3 topics 04
Joins & sets
Combine tables while preserving the intended grain.
2 topics 05
Aggregation
Summarize data and define meaningful denominators.
3 topics 06
Subqueries & CTEs
Break down problems and query related or hierarchical data.
4 topics 07
Window functions
Compare ordered rows without losing detail.
8 topics 08
Interview patterns
Recognize recurring problems and choose a reliable approach.
8 topics 09
Schema & data changes
Define tables, enforce constraints, and modify data safely.
4 topics 10
Database design
Model relationships, dependencies, and analytical history.
2 topics 11
Transactions
Understand concurrent work, isolation, and locks.
3 topics 12
Performance
Read plans, choose indexes, and reduce unnecessary work.
13 topics 13
Storage & scaling
Choose physical layout, distribution, and replication from workload requirements.
4 topics 14
PostgreSQL toolkit
Work with arrays, JSON, views, and database routines.
6 topics 15
Practice & revision
Apply the patterns, compare dialects, and test your understanding.
16 topics
Make the examples work for you
PostgreSQL is the main dialect. Each lesson states its assumptions; dialect-specific syntax is
labelled. Follow the reading order or search directly for a function or problem.
flowchart LR
accTitle: Make the examples work for you
A["State the output grain"] --> B["Run the query"] --> C["Add a duplicate, null, or tie"] --> D["Compare and explain the result"]
click B href "/coretrail/sql/foundations/sample-data/" "Open Run the query" _self
State the output grain
Run the query
Add a duplicate, null, or tie
Compare and explain the result
Before running a query, state the output grain. After running it, add a duplicate, a null, or a
tie. Explaining that second result is often where the learning happens.
Get the practice dataset
Sources & coverage