OR

Transact-SQL Reference

Transact-SQL Reference

OR

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.

Syntax

boolean_expression OR boolean_expression

Arguments

boolean_expression

Is any valid Microsoft® SQL Server™ expression that returns TRUE, FALSE, or UNKNOWN.

Result Types

Boolean

Result Value

OR returns TRUE when either of the conditions is TRUE.

Remarks

This table shows the result of the OR operator.

  TRUE FALSE UNKNOWN
TRUE TRUE TRUE TRUE
FALSE TRUE FALSE UNKNOWN
UNKNOWN TRUE UNKNOWN UNKNOWN
Examples

This example retrieves the book titles that carry an advance greater than $5,500 and 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)

See Also

Expressions

Functions

Operators (Logical Operators)

SELECT

WHERE