SQL course · 24 lessons · 6 stages
Learn SQL, one pattern at a time
Each lesson focuses on one SQL pattern, helping you write queries that return the results you expect. The lessons progress from basic to advanced. You can follow them in order or directly jump to any topic.
RequirementPaid or pending orders from India.
The query
SELECT order_id, country, statusFROM order_statusWHERE country = 'India' AND status = 'paid' OR status = 'pending';Result3 rows
order_idcountrystatus
1Indiapaid
3UKpending
4Indiapending
00 · Start hereIntroduction to Databases and SQLLearn what a database is, how relational databases organise data, and how SQL helps you work with it.
Read the intro →01
Foundations
Filter your query results.P01–P03P01Filtering Rows & ConditionsThe filter that keeps unintended rowsAND groups before OR. Parentheses define the logic you meant.13practice problems →
P02NULL & UnknownNULL changes how comparisons workHandle missing values correctly with IS NULL, COALESCE, and NULLIF.8practice problems →
P03Ordering & Top-NReturn the same top rows every timeUse ORDER BY, LIMIT, and tie-breakers to make Top-N queries stable.7practice problems →
Next · Summarising Data ↓02
Summarising Data
Turn rows into totals that answer the right question.P04–P06P04Aggregation & GROUP BYThe GROUP BY that answers a different questionOne extra grouping column splits a per-customer total into per-status rows.16practice problems →
P05Conditional Logic & CASEThe CASE that can never return LargeList a broader WHEN first and the specific category is unreachable.10practice problems →
P06Conditional AggregationThe COUNT that counts every rowCOUNT(CASE .. ELSE 0) counts non-NULL, so both 1 and 0 get counted.10practice problems →
Next · Combining Data ↓03
Combining Data
Join tables without inventing or losing rows.P07–P10P07JoinsThe LEFT JOIN that quietly becomes an INNERA right-table filter in WHERE drops the unmatched rows you meant to keep.17practice problems →
P08EXISTS & Anti-JoinsThe JOIN that answers a yes/no question with duplicatesAn INNER JOIN multiplies rows when you only needed to know a match exists.15practice problems →
P09Set OperationsThe UNION that quietly drops a rowUNION removes duplicate rows; UNION ALL keeps every meaningful record.13practice problems →
P10Subqueries & CTEsThe subquery that answers the wrong questionA missing correlation compares each row to the overall average, not its own group.15practice problems →
Next · Real-World Data ↓04
Real-World Data
Survive dates, strings, and types as they actually arrive.P11–P14P11Dates & TimestampsThe month that loses its final afternoonBETWEEN on a timestamp column stops at the start of the last day and drops the rest.20practice problems →
P12String FunctionsThe lookup that misses a value that looks identicalAn equality check fails on a stored value with hidden spaces or different capitalization.9practice problems →
P13Data Types & CASTThe numeric filter that quietly compares textDigits stored as text sort like characters, so '90' can outrank '1000' until you CAST.5practice problems →
P14JSON & Semi-structuredThe JSON number that compares as textExtracting a nested value gives you text, so '900' can outrank '1000' until you CAST.4practice problems →
Next · Analytical & Sequence ↓05
Analytical & Sequence
Rank, compare, and read order across rows.P15–P19P15Window Functions & RankingThe rank that skips a number after a tieRANK() leaves a gap after ties, so the third distinct value lands at rank 4, not 3.18practice problems →
P16Running Totals & Moving AveragesThe three rows mistaken for three daysA ROWS frame counts positions, not calendar time, so 2 PRECEDING can span a month.17practice problems →
P17LAG, LEAD & Value FunctionsThe previous row from the wrong sequenceA LAG without PARTITION BY compares one customer's order against another's.8practice problems →
P18Deduplication & Latest RowThe latest row that keeps changingA tied timestamp with no tie-breaker makes ROW_NUMBER pick a winner at random.12practice problems →
P19Gaps, Islands & StreaksThe streak that secretly counts twiceTwo events on one day inflate an active-day streak unless you fix the grain first.8practice problems →
Next · Advanced SQL ↓06
Advanced SQL
Reshape, recurse, and measure whole journeys.P20–P24P20Pivoting & ReshapingThe pivot that duplicates a customerAn extra GROUP BY column changes the grain, so one customer becomes several rows.14practice problems →
P21Recursive CTEs & HierarchiesThe join that finds only immediate childrenA single self-join follows one level; a recursive CTE repeats it to every descendant.11practice problems →
P22Funnels & ConversionThe funnel that counts the wrong orderCounting each stage independently credits users who did the steps out of sequence.6practice problems →