The Cassandra Select Command is used to fetch the rows from the Cassandra Table. If there is a where clause defined in the select query then it will fetch the records based on the condition mentioned in the where clause. If there no where clause is defined then the Select command will fetch the complete records.
The Cassandra Select Command fetches the records from the table. We can use the * to fetch the complete records from the table. To fetch the unique records, we can use the distinct command.
Syntax:SELECT * | select_expression | distinct partition
ORDER BY pkcolumnname ASC|DESC
Let's see some of the examples of the Cassandra Select command in the below section. We have already created the "emp_detail" table in the "Cloudduggu" keyspace and inserted the rows(Please refer to the Insert Table section for Create table and Insert Table commands).
Select All Rows From Table
We can use the * to fetch all rows in the select command. In the following example, we will fetch all from the Cloudduggu.emp_detail table.
Command:cqlsh> SELECT * FROM cloudduggu.emp_detail;
Select Specific Column From Table
We can read particular columns data by mentioning only those columns in the select list. In the below example we will access only emp_first_name and emp_last_name columns of the table Cloudduggu.emp_detail.
Command:cqlsh> SELECT emp_first_name, emp_last_name FROM cloudduggu.emp_detail;
Select Data with Where Clause
Using the Where Clause in the select command, we can restrict the row access and fetch only required rows. In the below example, we will fetch the record of an employee having empid=1003.