Documentation

SQL logical operators

Logical operators combine or manipulate conditions in a SQL query.

Operator Meaning
AND Returns true if both operands are true. Otherwise, returns false.
BETWEEN Returns true if the left operand is within the range of the right operand.
EXISTS Returns true if the results of a subquery are not empty.
IN Returns true if the left operand is in the right operand list.
LIKE Returns true if the left operand matches the right operand pattern string.
NOT Negates the subsequent expression.
OR Returns 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.

Character Description
% 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.

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: