Apache Cassandra 1.2 Documentation

Retrieving columns

To retrieve results, use the SELECT statement.

SELECT * FROM users WHERE first_name = 'jane' and last_name='smith';

Retrieving and sorting results

Similar to a SQL query, use the WHERE clause and then the ORDER BY clause to retrieve and sort results:

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

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

See the music service example for more information about using compound primary keys.

Using the keyspace qualifier

Sometimes it is inconvenient to have to issue a USE statement to select a keyspace. If you use connection pooling, for example, you have multiple keyspaces to juggle. Simplify tracking multiple keyspaces using the keyspace qualifier. Use the name of the keyspace followed by a period, then the table name. For example, Music.songs.

INSERT INTO Music.songs (id, title, artist, album) VALUES (
a3e64f8f-bd44-4f28-b8d9-6938726e34d4, 'La Grange', 'ZZ Top', 'Tres Hombres');

You can specify the keyspace you want to use in these statements:

  • ALTER TABLE
  • CREATE TABLE
  • DELETE
  • INSERT
  • SELECT
  • TRUNCATE
  • UPDATE

For more information, see the CQL Reference.