Retrieval using the IN keyword 

The IN keyword can define a set of clustering columns to fetch together, supporting a "multi-get" of CQL rows.

Similar to a SQL query, in CQL queries the IN keyword can define a set of clustering columns to fetch together, supporting a "multi-get" of CQL rows. A single clustering column can be defined if all preceding columns are defined for either equality or group inclusion. Alternatively, several clustering columns may be defined to collect several rows, as long as all preceding columns are queried for equality or group inclusion. The defined clustering columns can also be queried for inequality.

Note that using both IN and ORDER BY will require turning off paging with the PAGING OFF command in cqlsh.

Procedure

  • Turn off paging
    cqlsh> PAGING OFF
  • Retrieve and sort results in descending order.
    cqlsh> SELECT * FROM users WHERE userID IN (100,102,104) ORDER BY age DESC;
  • Retrieve rows using multiple clustering columns event_start_date and event_end_date. This example searches the partition key event_ids for several events, but the partition key can also be composed as an equality for one value.
    cqlsh> SELECT * FROM calendar WHERE event_id IN (100, 101, 102) AND (event_start_date, event_end_date) IN (('2015-05-09','2015-05-31'),('2015-05-06', '2015-05-31'));
  • Retrieve rows using multiple clustering columns event_start_date and event_end_date and inequality.
    cqlsh> SELECT * FROM calendar WHERE event_id IN (100, 101, 102) AND (event_start_date, event_end_date) >= ('2015-05-09','2015-05-24');