Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A decorator lists her tins of paint in a table Paints. Litres is the amount in each tin.
Tin Colour Finish Litres
P1 White Gloss 5
P2 Grey Matt 2
P3 White Matt 1
P4 White Gloss 3
P5 Grey Gloss 5Give the output of this script, and say how many records it outputs.
SELECT Tin
FROM Paints
WHERE Colour = 'White' AND Finish = 'Gloss';With AND a record passes only if both conditions are true; with OR it passes if at least one is true. A range is Field >= low AND Field <= high; outside a range is Field < low OR Field > high. Each part needs its own field name.
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. P1 is white and gloss: passes. P3 is white but matt: fails. P4 is white and gloss: passes. P5 is gloss but grey: fails.
Step 2. The output.
SELECT Tin
FROM Paints
WHERE Colour = 'White' AND Finish = 'Gloss';The output:
Tin
P1
P4Answer: P1 and P4, records.
Log in to join the discussion.
Loading…