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.

1
Q

What is the filtering clause keyword called?

A

WHERE - we may want to select a coat/record from the closet/table where the color is green

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are 6 comparison operators we can use with WHERE to filter numbers?

A

1) less than (<)
2) less than, equal to (<=)
3) equal to (=)
4) not equal to (<>)
5) greater than, equal to (>=)
6) greater than (>)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What comparison operator can be used with WHERE to filter strings?

A

= with single quotes around string we want to filter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Does WHERE come before or after the FROM statement?

A

After

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the order of execution on this query?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are three keywords that allow us to enhance our filters when using WHERE by adding multiple criteria?

A

1) OR
2) AND
3) BETWEEN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When do we use the OR operator with WHERE?

A

when we want to filter multiple criteria and only need to satisfy at least one condition (example, green or purple coat options)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True/False - We must specify the field for each OR condition in order for the query to run.

A

True - in the example, the invalid query has not specified what field or operator should be associated with the year 2000

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When do we use the AND operator with WHERE?

A

when we want to satisfy all criteria in our filter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

True/False - We do not need to specify the field for each AND condition in order for the query to run.

A

False - we must specify the field name separately for each AND condition as with OR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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.

A

True - enclose individual clauses in parenthesis

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a operator, other than AND, that we can use to specify values in a specific range?

A

BETWEEN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The BETWEEN operator is inclusive - this means the results contain what?

A

results contain the beginning and end values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True/False - Like the WHERE clause, the BETWEEN clause can be used with multiple AND and OR operators.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What three operators will help us filter a pattern rather than specific text?

A

1) LIKE
2) NOT LIKE
3) IN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the LIKE operator used for?

A

used to search for a pattern in a field

17
Q

What two wildcards are used with LIKE as a placeholder for some other value?

A

1) % match zero, one, or many characters
2) _ underscore match a single character

18
Q

What operator can we use to find records that don’t match the specified patter?

A

NOT LIKE - in this query below, we are looking for people who do not have A. as part of their first name

19
Q

True/False - Wildcards can be put anywhere and can be combined to find values that start, end, or contain characters in any position, as well as find records of certain length.

A

True

20
Q

What will this sample of code return?

A

all people whose name ends in r

21
Q

What will this sample of code return?

A

all records where the third character is t

22
Q

True/False - We could chain several ORs to the WHERE clause if we want to filter based on many conditions or a range of numbers.

A

True - but it can get messy doing it this way

23
Q

What operator allows us to specify multiple values in a WHERE clause, making it easier and quicker to set numerous OR conditions?

A

IN

24
Q

True/False - The WHERE IN operator can not be used with text fields.

A

False

25
Q

True/False - The COUNT(field_name) includes only non-missing values.

A

True

26
Q

True/False - The COUNT(*) does not include missing values.

A

False - COUNT(*) does include missing values

27
Q

In SQL, what does NULL represent?

A

a missing or unknown value

28
Q

What are 3reasons we may have missing values in a table?

A

1) human error
2) information not available
3) unknown

29
Q

What operator can we use with the WHERE clause to quickly see how much of our data is missing?

A

IS NULL - in the example here, we have checked to see which names do not have a recorded birthdate in our table

30
Q

What operator can we use with the WHERE clause to quickly see how much of our data is NOT missing?

A

IS NOT NULL - in the example the query on the right gives the count of all people whose birth dates are not missing in the people table