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.

Read more

InfluxDB v3 enhancements and InfluxDB Clustered is now generally available

New capabilities, including faster query performance and management tooling advance the InfluxDB v3 product line. InfluxDB Clustered is now generally available.

InfluxDB v3 performance and features

The InfluxDB v3 product line has seen significant enhancements in query performance and has made new management tooling available. These enhancements include an operational dashboard to monitor the health of your InfluxDB cluster, single sign-on (SSO) support in InfluxDB Cloud Dedicated, and new management APIs for tokens and databases.

Learn about the new v3 enhancements


InfluxDB Clustered general availability

InfluxDB Clustered is now generally available and gives you the power of InfluxDB v3 in your self-managed stack.

Talk to us about InfluxDB Clustered