productName price quantity color
----------- ----- -------- -----
pencil .25 100 yellow
pen .99 73 blue
paper 1.00 500 white
Mountain Dew 1.25 8 green
SELECT
productName
FROM products
WHERE
productName LIKE 'p%'
AND price < 1.00
productName
-----------
pencil
pen
SELECT
productName
FROM products
WHERE
productName LIKE 'p%'
OR price < 1.00
productName
-----------
pencil
pen
SELECT
productName
FROM products
WHERE
color = 'yellow'
OR color = 'green'
AND price < 1.00
productName
-----------
pencil
But you could easily have used parentheses, or you could have swapped the AND with the OR. The point of this exercise is to be aware of exactly what you are asking the parser to give you.
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)