Logical Expressions Flashcards
How does the WHERE clause evaluate rows of data?
The WHERE clause evaluates each row of data separately.
4.5
What do logical expressions ensure?
That only needed data, not unnecessary data, is returned by the query.
(4.6)
The most common form of a logical expression is: value1 operator value2
What do the values represent?
The values can be constants or columns from the database.
4.6
What four rules must logical expressions follow?
- Are made up of comparisons
- Evaluate to TRUE, FALSE, or UNKNOWN
- Can be combined with other expressions
- Must evaluate to TRUE to satisfy a condition
(4.6)
What are logical expressions made up of (literally)?
One or more values and an operator.
4.6
True or False:
Date/time columns are stored as a number of units since a specific time far in the past.
True.
Therefore, as far as comparisons are concerned, date A is considered less than date B if date A occurred before date B.
(4.6)
What type of quote should enclose string and date constants?
Single quotes.
4.6
What are the 6 two-value comparisons listed in the training manual?
- value1 = value 2 (Equal)
- value 1 < > value 2 (Not equal)
- value 1 < value 2 (Less than)
- value1 <= value 2 (Less than or equal)
- value1 > value 2 (Greater than)
- value1 >= value (Greater than or equal)
(4.7)
What is Three-Value Logic?
SQL uses a logical system known as three-value logic: all logical expressions evaluate to TRUE, FALSE, or UNKNOWN.
(4.8)
When do statements evaluate to UNKNOWN?
When there is insufficient data to make the comparison (if the value is NULL), the statement evaluates to UNKNOWN.
(4.9)
Is NULL equal to anything? What does a NULL mean?
No, not even itself.
When NULL appears in a comparison, there isn’t enough data to compute the expression.
PATIENT.CITY = NULL
This expression is never TRUE and never FALSE; it is always UNKNOWN.
(4.9)
What operator should you use to find NULL values?
The IS operator is used to check if a value is NULL.
The expression value IS NULL will always evaluate to TRUE for NULL values and FALSE for populated values.
(4.9)
When working with logical expressions, what keyword can be added to reverse TRUE and FALSE statements?
NOT
4.10
How would you reverse IS NULL?
Use IS NOT NULL
4.10
What does the statement NOT FALSE evaluate to?
TRUE
4.10
What does the statement NOT UNKNOWN evaluate to?
UNKNOWN
4.10
How would the Complex Comparison look for the following description:
• Greater than or equal to value2 and less than or equal to value3
value1 BETWEEN value2 AND value3
4.8
How would the Complex Comparison look for the following description:
• Less than value2 or greater than value3
value1 NOT BETWEEN value2 AND value3
4.8