Documentation

SQL logical operators

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!


Introducing InfluxDB Clustered

A highly available InfluxDB 3.0 cluster on your own infrastructure.

InfluxDB Clustered is a highly available InfluxDB 3.0 cluster built for high write and query workloads on your own infrastructure.

InfluxDB Clustered is currently in limited availability and is 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.

Learn more
Contact InfluxData Sales

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.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following:

State of the InfluxDB Cloud Serverless documentation

InfluxDB Cloud Serverless documentation is a work in progress.

The new documentation for InfluxDB Cloud Serverless is a work in progress. We are adding new information and content almost daily. Thank you for your patience!

If there is specific information you’re looking for, please submit a documentation issue.