CQL for Cassandra 2.x

Retrieving and sorting results

To retrieve results, use the SELECT command.
SELECT * FROM users WHERE first_name = 'jane' and last_name='smith';
Similar to a SQL query, in Cassandra 2.0.x use the WHERE clause and then the ORDER BY clause to retrieve and sort results, as shown in the following example. In Cassandra 2.1, you need to disable paging at the driver level to perform this query. In Java, set fetchsize to Integer.MAX_VALUE.

Procedure

  1. Retrieve and sort results in descending order.
    cqlsh:demodb> SELECT * FROM emp WHERE empID IN (130,104) ORDER BY deptID DESC;
     empid | deptid | first_name | last_name
    -------+--------+------------+-----------
       104 |     15 |       jane |     smith
       130 |      5 |     sughit |     singh
    
    (2 rows)
  2. Retrieve and sort results in ascending order.
    cqlsh:demodb> SELECT * FROM emp where empID IN (130,104) ORDER BY deptID ASC;
     empid | deptid | first_name | last_name
    
    -------+--------+------------+-----------
       130 |      5 |     sughit |     singh
       104 |     15 |       jane |     smith

    The music service example shows how to retrieve and sort results using compound primary keys.

Show/hide