Documentation

SQL logical operators

Limited availability

InfluxDB Clustered is currently only available to a limited group of InfluxData customers. If interested in being part of the limited access group, please contact the InfluxData Sales team.

Logical operators combine or manipulate conditions in a SQL query.

OperatorMeaning
ANDReturns true if both operands are true. Otherwise, returns false.
BETWEENReturns true if the left operand is within the range of the right operand.
EXISTSReturns true if the results of a subquery are not empty.
INReturns true if the left operand is in the right operand list.
LIKEReturns true if the left operand matches the right operand pattern string.
NOTNegates the subsequent expression.
ORReturns true if any operand is true. Otherwise, returns false.

Sample data

Query examples on this page use the following sample data sets:

AND

The AND operand returns true if both operands are true. Otherwise, it returns false. This operator is typically used in the WHERE clause to combine multiple conditions.

SELECT true AND false AS "AND condition"
AND condition
false
Examples

AND operator in the WHERE clause

BETWEEN

The BETWEEN operator returns true if the left numeric operand is within the range specified in the right operand. Otherwise, it returns false

SELECT 6 BETWEEN 5 AND 8 AS "BETWEEN condition"
BETWEEN condition
true
Examples

BETWEEN operator in the WHERE clause

EXISTS

The EXISTS operator returns true if result of a correlated subquery is not empty. Otherwise it returns false.

See SQL subquery operators.

Examples

EXISTS operator with a subquery in the WHERE clause

IN

The IN operator returns true if the left operand is in the right operand list or subquery result. Otherwise, it returns false.

SELECT 'John' IN ('Jane', 'John') AS "IN condition"
IN condition
true

See SQL subquery operators.

Examples

IN operator with a list in the WHERE clause

IN operator with a subquery in the WHERE clause

LIKE

The LIKE operator returns true if the left operand matches the string pattern specified in the right operand. LIKE expressions support SQL wildcard characters.

SELECT 'John' LIKE 'J_%n' AS "LIKE condition"
LIKE condition
true

LIKE operator in the WHERE clause

SQL wildcard characters

The InfluxDB SQL implementation supports the following wildcard characters when using the LIKE operator to match strings to a pattern.

CharacterDescription
%Represents zero or more characters
_Represents any single character

NOT

The NOT operator negates the subsequent expression.

SELECT NOT true AS "NOT condition"
NOT condition
false
Examples

NOT IN

NOT EXISTS

NOT BETWEEN

OR

The OR operator returns true if any operand is true. Otherwise, it returns false. This operator is typically used in the WHERE clause to combine multiple conditions.

SELECT true OR false AS "OR condition"
OR condition
true
Examples

OR in the WHERE clause


Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more