WHERE
WHERE
Using the WHERE statement, we can display subsets of tables based on conditions that must be met. You can also think of the WHERE command as filtering the data.
This video above shows how this can be used, and in the upcoming concepts, you will learn some common operators that are useful with the WHERE' statement.
Common symbols used in WHERE statements include:
>
(greater than)<
(less than)>=
(greater than or equal to)<=
(less than or equal to)=
(equal to)!=
(not equal to)
Solution from previous WHERE Questions
SELECT * FROM orders WHERE gloss_amt_usd >= 1000 LIMIT 5;
SELECT * FROM orders WHERE total_amt_usd < 500 LIMIT 10;
You will notice when using these WHERE statements, we do not need to ORDER BY unless we want to actually order our data. Our condition will work without having to do any sorting of the data.
WHERE with Non-Numeric Data
The WHERE statement can also be used with non-numeric data. We can use the =
and !=
operators here. You need to be sure to use single quotes (just be careful if you have quotes in the original text) with the text data, not double quotes.
Commonly when we are using WHERE with non-numeric data fields, we use the LIKE, NOT, or IN operators. We will see those before the end of this lesson!
Solution from WHERE with Non-Numeric Data
SELECT name, website, primary_poc FROM accounts WHERE name = 'Exxon Mobil';
Note: If you received an error message when executing your query, remember that SQL requires single-quotes, not double-quotes, around text values like 'Exxon Mobil.'
Comments
Post a Comment