CQL for Cassandra 2.0

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, use the WHERE clause and then the ORDER BY clause to retrieve and sort results.

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.