Add lesson 2: Filtering with WHERE
3 changed files with 35 additions and 0 deletions
lessons/02-filtering-with-where/README.md ADDED
| @@ -0,0 +1,21 @@ | ||
| 1 | +# Lesson 2: Filtering with WHERE | |
| 2 | + | |
| 3 | +This lesson covers filtering with WHERE. You'll read a short explanation, try three small exercises and finish with a quiz. | |
| 4 | + | |
| 5 | +Full lesson: [https://glibcode.net/courses/sql-essentials/lessons/2](https://glibcode.net/courses/sql-essentials/lessons/2) | |
| 6 | + | |
| 7 | +## Files | |
| 8 | + | |
| 9 | +- `where.sql`: filtering rows with WHERE, AND, IN and LIKE | |
| 10 | + | |
| 11 | +## Run it | |
| 12 | + | |
| 13 | +```sh | |
| 14 | +sqlite3 shop.db < ../../setup/schema.sql | |
| 15 | +sqlite3 shop.db < ../../setup/seed.sql | |
| 16 | +sqlite3 shop.db < where.sql | |
| 17 | +``` | |
| 18 | + | |
| 19 | +## Exercises | |
| 20 | + | |
| 21 | +See [exercises.md](exercises.md). Ask in the forum once you've tried. | |
lessons/02-filtering-with-where/exercises.md ADDED
| @@ -0,0 +1,5 @@ | ||
| 1 | +# Exercises: lesson 2 | |
| 2 | + | |
| 3 | +1. What happens with an empty input? Change the code so it handles that case with a clear message. | |
| 4 | +2. Add a comment above each block explaining what it does, in your own words. | |
| 5 | +3. Explain the example to someone who hasn't taken the course. Which part was hardest to explain? | |
lessons/02-filtering-with-where/where.sql ADDED
| @@ -0,0 +1,9 @@ | ||
| 1 | +SELECT name, city | |
| 2 | +FROM customers | |
| 3 | +WHERE city = 'Lisbon'; | |
| 4 | + | |
| 5 | +SELECT name, price | |
| 6 | +FROM products | |
| 7 | +WHERE price BETWEEN 10 AND 50 | |
| 8 | + AND category IN ('books', 'games') | |
| 9 | + AND name LIKE '%guide%'; | |