SELECT
productName
FROM products
WHERE
productName = 'Mountain Dew'
productName
-----------
Mountain Dew
The WHERE clause will let you limit the number of rows based on any column in the table you're querying. Now, I want to give you a heads up, you can only limit based on the values stored in the table. Any computed value like a SUM or COUNT will not work with the WHERE clause. I'll show you how to use those to limit the rows later.
SELECT
productName
FROM products
WHERE
productName like 'p%'
productName
-----------
pencil
pen
paper
SELECT
productName
FROM products
WHERE
productName IN ('pen','paper')
productName
-----------
pen
paper
Last we have BETWEEN, you'll use this most often when looking for records between two values. A simple example of the between clause would be to show all productNames that have a price between $2.50 and $25.00.
SELECT
productName
FROM products
WHERE
price between 2.50 and 25.00
Experiment with the WHERE clause. If you have any questions, please, feel free to comment below! I'm here to help you grow stronger in the ways of The Force, err... SQL.
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)