Restriction Clauses
A restriction clause is an ASCII text string of operators and expressions. A restriction clause specifies selection criteria for the values in the columns of a view, limiting the number of rows the view contains. The syntax of certain clauses (such as WHERE or HAVING) requires using a restriction clause. A restriction clause can specify these conditions:
A restriction clause can contain multiple conditions. It can also contain a SELECT subquery that bases search criteria on the contents of other tables in the database. The condition containing the subquery can contain the EXISTS, NOT EXISTS, ALL, ANY, and SOME keywords, or the IN range operator.
You can specify a restriction clause using a WHERE or HAVING clause in a SELECT, UPDATE, or DELETE statement.
Figure 1 provides an example restriction clause and illustrates restriction clause elements.
Figure 1 Example Restriction Clause
Restriction Clause Operators
Restriction clauses can use three types of operators:
Boolean Operators
Boolean operators specify logical conditions.
Condition Operators
A condition operator can be a relational or a range operator.
Table 44 lists the relational operators.
Table 45 lists the condition operators.
With the IN and NOT IN operators, the second expression can be a subquery instead of a column name or constant.
Expression Operators
Expression operators allow you to create expressions for computed columns using arithmetic or string operators. For more information, refer to Functions.
Restriction Clause Examples
The following examples demonstrate some of the restriction clause operators.
OR and Equal To (=)
The following example uses the relational EQUAL TO and boolean OR operators. It selects all rows in which the value of the State column is Texas or New Mexico.
SELECT Last_Name, First_Name, State
FROM Person
WHERE State = 'TX' OR State = 'NM'#
IN
The following example uses the IN operator. It selects the records from the Person table where the first names are Bill and Roosevelt.
SELECT * FROM Person WHERE First_name IN
(’Roosevelt’, ’Bill’)#
LIKE
The following example uses the LIKE operator:
SELECT ID, First_Name, Last_Name, Zip
FROM Person
WHERE Zip LIKE '787%';
This example retrieves records in the Person table where the zip code begins with ‘787’.