Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A city farm keeps a table of its animals, Animals.
AnimalID Name Kind Legs
Z1 Rosa Bird 2
Z2 Bram Goat 4
Z3 Kiki Bird 2
Z4 Taro Pony 4
Z5 Pip Bird 2
Z6 Nell Goat 4Write down the output of this script and say how many records it outputs.
SELECT Name
FROM Animals
WHERE Kind = 'Bird';WHERE keeps only the records for which the condition is true. The operators are =, <>, >, <, >= and <=. Text goes in quotes, numbers do not, and a Boolean field is compared with TRUE or FALSE. The field in the condition need not be selected.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. Test each record. The kinds are Bird, Goat, Bird, Pony, Bird, Goat. The condition is true for the first, third and fifth records.
Step 2. Output the selected field.
SELECT Name
FROM Animals
WHERE Kind = 'Bird';The output:
Name
Rosa
Kiki
PipAnswer: Rosa, Kiki and Pip: records.
Log in to join the discussion.
Loading…