SQL lessons
Free SQL lessons from your first SELECT to window functions, plus practice checking SQL written by AI. Each one ends with a task to try in your browser. New lessons are added as the course grows.
Unit 1: Your first queries Foundations
- Your first query: SELECT and FROMUnit 1, lesson 1 · SELECT, FROM
- Renaming columns with AS, previewing with LIMITUnit 1, lesson 2 · AS, LIMIT
- Filtering rows with WHEREUnit 1, lesson 3 · WHERE with numbers
- Matching text exactlyUnit 1, lesson 4 · WHERE with text
- Combining conditions with AND and ORUnit 1, lesson 5 · AND, OR
- Lists of values with IN, and comparing datesUnit 1, lesson 6 · IN, comparing dates
- Sorting with ORDER BY and keeping the top rowsUnit 1, lesson 7 · ORDER BY, LIMIT
- Unit 1 review: putting it togetherUnit 1, lesson 8 · Unit 1 challenge
- Checking AI-written SQL: does it answer the question?Unit 1, Checking AI-written SQL · Checking AND and OR
Unit 2: Cleaner results Foundations
- Removing duplicates with DISTINCTUnit 2, lesson 1 · DISTINCT
- Searching text with LIKE and LOWERUnit 2, lesson 2 · LIKE, LOWER
- Filtering a date rangeUnit 2, lesson 3 · Date ranges, BETWEEN
- Missing values: NULLUnit 2, lesson 4 · NULL, IS NULL
- Calculated columns and ROUNDUnit 2, lesson 5 · Calculations, ROUND
- Missing values in calculations: COALESCEUnit 2, lesson 6 · COALESCE
- Counting rows with COUNTUnit 2, lesson 7 · COUNT
- Summarizing a table: MIN, MAX, AVG and SUMUnit 2, lesson 8 · MIN, MAX, AVG, SUM
- Unit 2 review: putting it togetherUnit 2, lesson 9 · Unit 2 challenge
- Checking AI-written SQL: where do the NULLs go?Unit 2, Checking AI-written SQL · Checking NULL handling
Unit 3: Working with text Foundations
- Tidy text with UPPER and TRIMUnit 3, lesson 1 · UPPER, TRIM
- How long is it? LENGTHUnit 3, lesson 2 · LENGTH
- Pieces of text with SUBSTRUnit 3, lesson 3 · SUBSTR
- Gluing text together with ||Unit 3, lesson 4 · ||
- Fixing text with REPLACEUnit 3, lesson 5 · REPLACE
- Finding text inside text with POSITIONUnit 3, lesson 6 · POSITION
- Unit 3 review: cleaning textUnit 3, lesson 7 · Unit 3 challenge
- Checking AI-written SQL: text that only looks the sameUnit 3, Checking AI-written SQL · Checking text matches
Unit 4: Dates and times Foundations
- Pieces of a date: EXTRACT and to_charUnit 4, lesson 1 · EXTRACT, to_char
- Moving a date: adding days and intervalsUnit 4, lesson 2 · Adding days, INTERVAL
- Days between two datesUnit 4, lesson 3 · Subtracting dates
- Rolling a date back to its month or weekUnit 4, lesson 4 · date_trunc, CAST
- Day of the week: DOW and ISODOWUnit 4, lesson 5 · Day of the week
- Unit 4 review: datesUnit 4, lesson 6 · Unit 4 challenge
- Checking AI-written SQL: which March?Unit 4, Checking AI-written SQL · Checking date filters