Operators
Comparison
| Operator | Description | Example |
|---|---|---|
= |
Equal to | WHERE Status = 'active' |
!= or <> |
Not equal to | WHERE Status != 'churned' |
> |
Greater than | WHERE Revenue > 50000 |
< |
Less than | WHERE Revenue < 1000 |
>= |
Greater than or equal | WHERE Revenue >= 50000 |
<= |
Less than or equal | WHERE Revenue <= 1000 |
IN |
Matches any value in list | WHERE Status IN ('a', 'b') |
NOT IN |
Does not match any value | WHERE Status NOT IN ('a', 'b') |
BETWEEN |
Within a range (inclusive) | WHERE Revenue BETWEEN 10000 AND 50000 |
NOT BETWEEN |
Outside a range | WHERE Revenue NOT BETWEEN 0 AND 100 |
LIKE |
Pattern match (% = any chars, _ = one char) |
WHERE Name LIKE '%Tech%' |
NOT LIKE |
Does not match pattern | WHERE Name NOT LIKE '%test%' |
IS NULL |
Value is null | WHERE Website IS NULL |
IS NOT NULL |
Value is not null | WHERE Website IS NOT NULL |
Logical
| Operator | Description | Example |
|---|---|---|
AND |
Both conditions must be true | WHERE a > 1 AND b < 10 |
OR |
Either condition must be true | WHERE a > 1 OR b < 10 |
NOT |
Negates a condition | WHERE NOT Status = 'deleted' |
( ) |
Group conditions | WHERE (a OR b) AND c |
Arithmetic
| Operator | Description | Example |
|---|---|---|
+ |
Addition | SELECT price + tax |
- |
Subtraction | SELECT revenue - costs |
* |
Multiplication | SELECT price * quantity |
/ |
Division | SELECT total / count |
|| |
String concatenation | SELECT first || ' ' || last |
Array operators (CONTAINS family)
For columns that hold multiple values (tags, multi-select), use CONTAINS to filter by array membership.
| Operator | Description |
|---|---|
CONTAINS value |
Array includes the value |
CONTAINS ANY (a, b, ...) |
Array includes at least one of the listed values |
CONTAINS ALL (a, b, ...) |
Array includes every listed value |
CONTAINS ONLY (a, b, ...) |
Array contains exactly these values and nothing else |
NOT CONTAINS value |
Array does not include the value |
NOT CONTAINS ANY (a, b, ...) |
Array does not include any of the listed values |
NOT CONTAINS ALL (a, b, ...) |
Array does not include all of the listed values simultaneously |
-- Row has a specific tag
WHERE Tags CONTAINS 'urgent'
-- Row has ANY of these tags (at least one match)
WHERE Tags CONTAINS ANY ('urgent', 'high-priority', 'escalated')
-- Row has ALL of these tags (every value must be present)
WHERE Tags CONTAINS ALL ('frontend', 'bug', 'p1')
-- Row has EXACTLY these tags (no more, no less)
WHERE Tags CONTAINS ONLY ('frontend', 'bug')
-- Negation
WHERE Tags NOT CONTAINS 'spam'
WHERE Tags NOT CONTAINS ANY ('spam', 'test', 'duplicate')
CONTAINSonly works on array-type columns (tags, multi-select). Using it on a text or number column won't produce meaningful results.
Operator precedence
KSQL follows standard SQL precedence:
- Parentheses
( ) - Unary minus,
NOT - Multiplicative:
*,/,|| - Additive:
+,- - Comparison:
=,!=,<,>,<=,>=,LIKE,IN,BETWEEN,IS NULL,CONTAINS - Logical
AND - Logical
OR
When in doubt, add parentheses — they cost nothing and make intent obvious.
Next
- Expressions → — CASE WHEN, arithmetic in SELECT
- Functions → — built-in function reference