Previous Topic: The WHERE ClauseNext Topic: Using Comparison Operators in Predicates


Comparison Operators and Keywords in Predicates

You use a predicate to compare one value to another. The values compared in the predicate must be of compatible data types. For example, a column defined as a character data type cannot be compared to a column defined as an integer data type even though the character string contains numbers.

Check the Data Type When Comparing

The table layout specifies whether the column you want to compare is defined as a character data type. A column may appear to contain numeric data when you look at the values stored in the database, although it is actually defined as character. For example, the SKILL_LEVEL column in the EXPERTISE table is defined as a character column but usually contains numeric data.

Entering Character Literals

Use single quotation marks if you use a character literal such as 'Smith' and enter the literal with uppercase and lowercase letters exactly as you expect it exists in the database.

Ways You Can Compare Values

You can use these operators to compare values:

Comparison operator

Meaning

=

Equal to

<>

Not equal to

>

Greater than

<

Less than

>=

Greater than or equal to

<=

Less than or equal to

You can use these keywords to compare values:

Keyword

Meaning

IS NULL

Checks whether a value is null

BETWEEN

Locates values within a range of values

IN

Locates values identified by specific values in a list

LIKE

Retrieves rows based on character combinations in a nonnumeric column