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"
  • Copy
  • Fill window
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"
  • Copy
  • Fill window
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"
  • Copy
  • Fill window
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"
  • Copy
  • Fill window
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"
  • Copy
  • Fill window
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"
  • Copy
  • Fill window
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 3 Core and Enterprise are now in Beta

InfluxDB 3 Core and Enterprise are now available for beta testing, available under MIT or Apache 2 license.

InfluxDB 3 Core is a high-speed, recent-data engine that collects and processes data in real-time, while persisting it to local disk or object storage. InfluxDB 3 Enterprise is a commercial product that builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries. A free tier of InfluxDB 3 Enterprise will also be available for at-home, non-commercial use for hobbyists to get the full historical time series database set of capabilities.

For more information, check out:

InfluxDB Cloud Serverless