Logical (binary) operators

Learn how to use Logical (binary) operators to return a Boolean result.

The following logical operators can be used to perform comparisons and evaluations:

Operator nameSyntaxMeaning
Equality==Returns true if both operands are non-null and equal to each other. Otherwise, returns false.
Inequality!=Returns true if any of the operands are null or if the operands aren’t equal to each other. Otherwise, returns false.
Logical andandReturns true only if both operands are true. The logical and has higher precedence than the logical or.
Logical ororReturns true if either of the operands is true, regardless of the other operand.

How logical operators work with null values

Null values adhere to the following rules:

OperationResult
bool(null) == bool(null)false
bool(null) != bool(null)false
bool(null) and truefalse
bool(null) or truetrue

Examples

Equality

The following query returns a count of all storm events where the event type is “Tornado”.

StormEvents
| where EventType == "Tornado"
| count

Output

Count
1238

Inequality

The following query returns a count of all storm events where the event type isn’t “Tornado”.

StormEvents
| where EventType != "Tornado"
| count

Output

Count
57828

Logical and

The following query returns a count of all storm events where the event type is “Tornado” and the state is “KANSAS”.

StormEvents
| where EventType == "Tornado" and State == "KANSAS"
| count

Output

Count
161

Logical or

The following query returns a count of all storm events where the event type is “Tornado” or “Thunderstorm Wind”.

StormEvents
| where EventType == "Tornado" or EventType == "Thunderstorm Wind"
| count

Output

Count
14253

Null values

The following query shows that null values are treated as false.

print print=iff(bool(null) and true, true, false)

Output

print
false