Combines two conditions. When more than one logical operator is used in a statement, OR operators are evaluated after AND operators. However, you can change the order of evaluation by using parentheses.
boolean_expression OR boolean_expression
Boolean
OR returns TRUE when either of the conditions is TRUE.
The table shows the result of the OR operator.
TRUE | FALSE | UNKNOWN | |
---|---|---|---|
TRUE | TRUE | TRUE | TRUE |
FALSE | TRUE | FALSE | UNKNOWN |
UNKNOWN | TRUE | UNKNOWN | UNKNOWN |
This example retrieves the book titles that carry an advance greater than $5,500 and that are either business or psychology books. If the parentheses are not included, the WHERE clause retrieves all business books or psychology books that have an advance greater than $5,500.
USE pubs
GO
SELECT SUBSTRING(title, 1, 30) AS Title, type
FROM titles
WHERE (type = 'business' OR type = 'psychology') AND
advance > $5500
ORDER BY title
GO
Here is the result set:
Title type
------------------------------ ------------
Computer Phobic AND Non-Phobic psychology
Life Without Fear psychology
You Can Combat Computer Stress business
(3 row(s) affected)
Expressions | SELECT |
Functions | WHERE |
Operators (Logical Operators) |