sql · level 2 · unit 4 · lesson 1
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
checks a value against a whole list.
WHERE kind = 'fruit' OR kind = 'sweet' works, but it grows long fast. WHERE kind IN ('fruit', 'sweet') says the same thing: keep the row if its kind matches any item in the brackets.
The list goes in brackets, with commas between the items. Text keeps its single quotes and numbers do not, like WHERE age IN (1, 3, 5).
flips it, keeping only the rows whose value matches nothing in the list.
SELECT name, kind FROM snacks
WHERE kind IN ('fruit', 'sweet')
ORDER BY name; If the list holds a NULL, NOT IN matches nothing at all, so keep NULL out of the list.
guess first
Which films are left?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
SELECT title FROM films
WHERE genre NOT IN ('comedy', 'adventure')
ORDER BY year;
your turn
Your turn. Pick some players.
Type two or three names between the brackets, each in single quotes, with commas between: 'Mia', 'Leo', 'Ava' or 'Sam'.
result
Your answer appears here as a table.
fix it
Cats and dogs only. Fix the list!
result
Your answer appears here as a table.
- Read the error. Which value is it near?
- Items in a list need something between them, the same as columns in
SELECT. - Put a comma after 'cat', then press run.
nailed it
you matched against a whole list. :D
IN (...)keeps rows that match any item in the list.NOT IN (...)keeps rows that match none of them.- Keep
NULLout of aNOT INlist.
new words in your collection
- IN
- NOT IN
This lesson isn’t saved. A free account remembers every lesson you finish.