Skip to content

Latest commit

 

History

History
96 lines (74 loc) · 3.37 KB

or-transact-sql.md

File metadata and controls

96 lines (74 loc) · 3.37 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic ms.custom f1_keywords helpviewer_keywords dev_langs monikerRange
OR (Transact-SQL)
OR (Transact-SQL)
rwestMSFT
randolphwest
03/15/2017
sql
t-sql
reference
ignite-2024
OR_TSQL
OR
conditions [SQL Server], combining
combining conditions
OR operator
TSQL
>=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric

OR (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb]

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.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

boolean_expression OR boolean_expression  

Arguments

boolean_expression
Is any valid expression that returns TRUE, FALSE, or UNKNOWN.

Result Types

Boolean

Result Value

OR returns TRUE when either of the conditions is TRUE.

Remarks

The following table shows the result of the OR operator.

TRUE FALSE UNKNOWN
TRUE TRUE TRUE TRUE
FALSE TRUE FALSE UNKNOWN
UNKNOWN TRUE UNKNOWN UNKNOWN

Examples

The following example uses the vEmployeeDepartmentHistory view to retrieve the names of Quality Assurance personnel who work either the evening shift or the night shift. If the parentheses are omitted, the query returns Quality Assurance employees who work the evening shift and all employees who work the night shift.

-- Uses AdventureWorks  
  
SELECT FirstName, LastName, Shift   
FROM HumanResources.vEmployeeDepartmentHistory  
WHERE Department = 'Quality Assurance'  
   AND (Shift = 'Evening' OR Shift = 'Night');  

[!INCLUDEssResult]

FirstName    LastName         Shift 
------------ ---------------- ------- 
Andreas      Berglund         Evening 
Sootha       Charncherngkha   Night

Examples: [!INCLUDEssazuresynapse-md] and [!INCLUDEssPDW]

The following example retrieves the names of employees who either earn a BaseRate less than 20 or have a HireDate January 1, 2001 or later.

-- Uses AdventureWorks  
  
SELECT FirstName, LastName, BaseRate, HireDate   
FROM DimEmployee  
WHERE BaseRate < 10 OR HireDate >= '2001-01-01';  

See Also

Expressions (Transact-SQL)
Built-in Functions (Transact-SQL)
Operators (Transact-SQL)
SELECT (Transact-SQL)
WHERE (Transact-SQL)