CQL Read Data

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Cassandra READ Data

SELECT command is used to read data from Cassandra table. You can use this command to read a whole table, a single column, a particular cell etc.

Syntax:

  1. SELECT FROM <tablename>   

Example:

Let's take an example to demonstrate how to read data from Cassandra table. We have a table named "student" with columns (student_id, student_fees student_name)


Read the whole table using SELECT command

  1. SELECT * FROM student;  

Cassandra Read date 1


Read Particular Columns

This example will read only student_name and student_id from the student table.

  1. SELECT student_id, student_name FROM student;   

Cassandra Read date 2


Use of WHERE Clause

WHERE clause is used with SELECT command to specify the exact location from where we have to fetch data.

Syntax:

  1. SELECT FROM <table nameWHERE <condition>;   

Note: WHERE clause can be used only on the columns that are a part of primary key or have a secondary index on them.

Example:

  1. SELECT * FROM student WHERE student_id=2;  

Cassandra Read date 3