Retrieving and sorting results

Using the SELECT command.

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. 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.