The IN operator

So we've seen that CQL has an AND keyword for specifying multiple filters in the WHERE clause. Does it also have an OR keyword, like SQL?

No, it does not. This is because Apache Cassandra is designed to serve sequential reads, not random reads. It works best when its queries give it a clear, precise path to the requested data. Allowing filters in the WHERE clause to be specified on an OR basis would force Cassandra to perform random reads, which really works against how it was built.

However, queries can be made to perform similarly to OR, via the IN operator:

SELECT * FROM query_test WHERE pk1='a' AND pk2 IN ('b','c');

While this query technically will work, its use is considered to be an anti-pattern in Cassandra. This is ...

Get Mastering Apache Cassandra 3.x - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.