SQL

Ask data questions

SQL

SELECT, WHERE, JOIN, GROUP BY. Query real tables in your browser and learn how apps actually remember things.

0 / 12 lessons done
  1. 01 Tables and your first SELECTWhat a database and a table actually are, and how to read a whole table with SELECT * FROM. Your first real SQL query, run in the browser. 2 exercises
  2. 02 Picking columns and naming themChoose exactly which columns a SQL query returns, do maths on them, and rename results with AS so the output makes sense. 2 exercises
  3. 03 Filtering rows with WHEREUse WHERE to keep only the rows you want. Compare numbers and text with =, <>, <, >, <= and >= in SQL, and learn why text needs quotes. 2 exercises
  4. 04 AND, OR, IN, BETWEEN and LIKECombine SQL conditions with AND and OR, match lists with IN, ranges with BETWEEN and text patterns with LIKE. Plus the brackets trap. 2 exercises
  5. 05 Sorting with ORDER BY and LIMITSort SQL results with ORDER BY, ASC and DESC, break ties with a second column, and use LIMIT to get a top 3 leaderboard. 2 exercises
  6. 06 NULL, the value that isn't thereWhat NULL means in SQL, why WHERE mark = NULL never matches anything, and how to use IS NULL, IS NOT NULL and COALESCE instead. 2 exercises
  7. 07 Counting and adding upSummarise a whole table in one row with COUNT, SUM, AVG, MIN and MAX. Learn the difference between COUNT(*) and COUNT(column). 2 exercises
  8. 08 GROUP BY and HAVINGUse GROUP BY to get one summary row per customer or category, and HAVING to filter those groups. Learn when to use WHERE and when to use HAVING. 2 exercises
  9. 09 Joining two tablesWhy data is split across tables, and how INNER JOIN ... ON puts it back together. Match students to their clubs using ids. 2 exercises
  10. 10 LEFT JOIN and the missing matchesKeep every row from one table with LEFT JOIN, even when nothing matches, and use IS NULL to find things with no match, like empty clubs. 2 exercises
  11. 11 INSERT, UPDATE and DELETEChange data with INSERT, UPDATE and DELETE in SQL, and avoid the classic disaster of running UPDATE or DELETE without a WHERE. 3 exercises
  12. 12 Queries inside queriesUse a subquery to feed one SQL query's answer into another, like finding every song longer than the average or artists with no plays. 2 exercises

Projects for this track

FreeSQL · 30 min

Playlist stats

Answer real questions about a playlist: top artists, total minutes, the longest song. GROUP BY gets a workout.

  1. Count songs per artist and sort by the count.
  2. Find the total playlist length in minutes.
  3. Find the longest song with ORDER BY and LIMIT.
Start in the playground
FreeSQL · 35 min

Tuck shop sales

A week of tuck shop sales in two tables. Find the best seller, the busiest day and the snack nobody bought. JOIN, GROUP BY and a LEFT JOIN that earns its keep.

  1. Show how many of each product were sold, best seller first, using JOIN and GROUP BY.
  2. Find the day with the most money taken. You need SUM(qty * price).
  3. List any product that was never sold, using LEFT JOIN and IS NULL.
Start in the playground
Pro, coming soonSQL · 2 hours

Design a school database

Design tables for students, classes and grades from scratch, then answer the questions a timetable office actually asks.

Get told when it opens