UPDATESQL

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

  1. Your first query: SELECT and FROMUnit 1, lesson 1 · SELECT, FROM
  2. Renaming columns with AS, previewing with LIMITUnit 1, lesson 2 · AS, LIMIT
  3. Filtering rows with WHEREUnit 1, lesson 3 · WHERE with numbers
  4. Matching text exactlyUnit 1, lesson 4 · WHERE with text
  5. Combining conditions with AND and ORUnit 1, lesson 5 · AND, OR
  6. Lists of values with IN, and comparing datesUnit 1, lesson 6 · IN, comparing dates
  7. Sorting with ORDER BY and keeping the top rowsUnit 1, lesson 7 · ORDER BY, LIMIT
  8. Unit 1 review: putting it togetherUnit 1, lesson 8 · Unit 1 challenge
  9. Checking AI-written SQL: does it answer the question?Unit 1, Checking AI-written SQL · Checking AND and OR

Unit 2: Cleaner results Foundations

  1. Removing duplicates with DISTINCTUnit 2, lesson 1 · DISTINCT
  2. Searching text with LIKE and LOWERUnit 2, lesson 2 · LIKE, LOWER
  3. Filtering a date rangeUnit 2, lesson 3 · Date ranges, BETWEEN
  4. Missing values: NULLUnit 2, lesson 4 · NULL, IS NULL
  5. Calculated columns and ROUNDUnit 2, lesson 5 · Calculations, ROUND
  6. Missing values in calculations: COALESCEUnit 2, lesson 6 · COALESCE
  7. Counting rows with COUNTUnit 2, lesson 7 · COUNT
  8. Summarizing a table: MIN, MAX, AVG and SUMUnit 2, lesson 8 · MIN, MAX, AVG, SUM
  9. Unit 2 review: putting it togetherUnit 2, lesson 9 · Unit 2 challenge
  10. Checking AI-written SQL: where do the NULLs go?Unit 2, Checking AI-written SQL · Checking NULL handling

Unit 3: Working with text Foundations

  1. Tidy text with UPPER and TRIMUnit 3, lesson 1 · UPPER, TRIM
  2. How long is it? LENGTHUnit 3, lesson 2 · LENGTH
  3. Pieces of text with SUBSTRUnit 3, lesson 3 · SUBSTR
  4. Gluing text together with ||Unit 3, lesson 4 · ||
  5. Fixing text with REPLACEUnit 3, lesson 5 · REPLACE
  6. Finding text inside text with POSITIONUnit 3, lesson 6 · POSITION
  7. Unit 3 review: cleaning textUnit 3, lesson 7 · Unit 3 challenge
  8. Checking AI-written SQL: text that only looks the sameUnit 3, Checking AI-written SQL · Checking text matches

Unit 4: Dates and times Foundations

  1. Pieces of a date: EXTRACT and to_charUnit 4, lesson 1 · EXTRACT, to_char
  2. Moving a date: adding days and intervalsUnit 4, lesson 2 · Adding days, INTERVAL
  3. Days between two datesUnit 4, lesson 3 · Subtracting dates
  4. Rolling a date back to its month or weekUnit 4, lesson 4 · date_trunc, CAST
  5. Day of the week: DOW and ISODOWUnit 4, lesson 5 · Day of the week
  6. Unit 4 review: datesUnit 4, lesson 6 · Unit 4 challenge
  7. Checking AI-written SQL: which March?Unit 4, Checking AI-written SQL · Checking date filters

Unit 7: Grouping and counting Foundations

  1. Counting with GROUP BYUnit 7 · GROUP BY, COUNT

Unit 9: Joining tables Analyst core

  1. Joining tables and adding up valuesUnit 9 · JOIN, SUM
  2. Checking AI-written SQL: did a join multiply the rows?Unit 9, Checking AI-written SQL · Checking joins

Unit 10: Outer joins Analyst core

  1. Finding missing matches with LEFT JOINUnit 10 · LEFT JOIN, NULL

Unit 15: Conditional aggregation Analyst core

  1. Percentages, subqueries and integer divisionUnit 15 · Subqueries, integer math

Unit 20: Running and moving totals Interview ready

  1. Running totals with window functionsUnit 20 · Window functions