Intermediate SQL - Filtering Records Flashcards
Learn about how you can filter numerical and textual data with SQL. Filtering is an important use for this language. You’ll learn how to use new keywords and operators to help you narrow down your query to get results that meet your desired criteria and gain a better understanding of NULL values and how to handle them.
What is the filtering clause keyword called?
WHERE - we may want to select a coat/record from the closet/table where the color is green
What are 6 comparison operators we can use with WHERE to filter numbers?
1) less than (<)
2) less than, equal to (<=)
3) equal to (=)
4) not equal to (<>)
5) greater than, equal to (>=)
6) greater than (>)
What comparison operator can be used with WHERE to filter strings?
= with single quotes around string we want to filter
Does WHERE come before or after the FROM statement?
After
What is the order of execution on this query?
1) FROM
2) WHERE
3) SELECT
4) LIMIT
We go to the closet we want to get the coat from, find where the green coats are, and select five of them.
What are three keywords that allow us to enhance our filters when using WHERE by adding multiple criteria?
1) OR
2) AND
3) BETWEEN
When do we use the OR operator with WHERE?
when we want to filter multiple criteria and only need to satisfy at least one condition (example, green or purple coat options)
True/False - We must specify the field for each OR condition in order for the query to run.
True - in the example, the invalid query has not specified what field or operator should be associated with the year 2000
When do we use the AND operator with WHERE?
when we want to satisfy all criteria in our filter
True/False - We do not need to specify the field for each AND condition in order for the query to run.
False - we must specify the field name separately for each AND condition as with OR
True/False - If a query has multiple filtering conditions, we will need to enclose the individual clauses in parentheses to ensure the correct execution order; otherwise, we ma not get the expected result.
True - enclose individual clauses in parenthesis
What is a operator, other than AND, that we can use to specify values in a specific range?
BETWEEN
The BETWEEN operator is inclusive - this means the results contain what?
results contain the beginning and end values
True/False - Like the WHERE clause, the BETWEEN clause can be used with multiple AND and OR operators.
True
What three operators will help us filter a pattern rather than specific text?
1) LIKE
2) NOT LIKE
3) IN