CQL Clauses – Select, Where, OrderBy Clauses in Cassandra

Keeping you updated with latest technology trends, Join DataFlair on Telegram

1. Objective

In this Cassandra Tutorial, we will discuss the CQL clauses that are used along with different commands. CQL clauses are used to specify data that has to be used in a program or application. A user can select a column data and perform any operation using other CQL commands.
So, let’s begin CQL Clauses.

CQL Clauses - Select, Where, OrderBy Clauses

CQL Clauses – Select, Where, OrderBy Clauses

Do you know top Cassandra Features

2. CQL Clauses

Cassandra Query Langauge (CQL), has three major types of clauses, let’s discuss them one by one:

a. SELECT Clause

There are some programs that have to use a specific data from a table. In such programs, the user has to derive a particular set of data. The user can use a SELECT keyword to use a particular field in a table.
Let’s See How Cassandra Stores Data or Cassandra Data Model
A syntax of SELECT Clause:

SELECT <identifier> FROM <table name>;

In the syntax, the identifier is basically a field that has to be selected from a particular table. If the identifier is ‘*’, it means the user will select the whole table.
Example: In this example, we will first select a particular field from the table below. And in next set, we will select the whole table.
Table.1 CQL Clauses – SELECT Clause

Id Name Branch Phone number
001 Ayush Electrical Engineering 9877656543
002 Aaron Computer Engineering 9867767689
003 Kabir Applied Physics 8769878762

First, we will select the field ‘Branch’.

cqlsh; keyspace1> SELECT Branch FROM student;

Now, to select the full table, the code is,

cqlsh;keyspace1> SELECT Branch FROM student;

Let’s Learn Architecture of Cassandra in Detail

b. WHERE Clause

WHERE clause is a bit more specific than SELECT. In SELECT the user selects a field, whereas in WHERE clause the user can select a particular data. In other words, the data is specific to a particular cell of a table. This clause is used along with SELECT cause, in which WHERE acts as a condition.
A Syntax of WHERE Clause:

SELECT<field name>FROM<table name>WHERE<identifier>;

Example: In this example, we will select a particular cell ‘Computer Engineering’ from the previous table. And in the next set, we will select a whole row of a table by using ‘*’.

cqlsh;keyspace1> SELECT Branch FROM student WHERE Id=002;

Now to select the whole row;

cqlsh;keyspace1>SELECT * FROM student WHERE Id=002;

Do you know Cassandra Curd Operation – Create, Update, Read & Delete

c. ORDERBY Clause

There are applications that require a particular set of data in a particular set of order. To perform this operation the user can use ORDERBY clause along with SELECT clause.
A Syntax of ORDERBY Clause:

SELECT<field name>FROM<table name>ORDERBY<identifier>;

Example: In this example, we will arrange the table according to a phone number.

cqlsh;keyspace1> SELECT*FROM student ORDERBY Phone number;

Have a look at Cassandra Data Definition Command

So, this was all about CQL Clauses Tutorial. Hope you like our explanation.

3. Conclusion

Hence, in this Cassandra Query Language Clauses Tutorial, we discussed CQL CLAUSES: SELECT Clause, WHERE Clause & ORDERBY Clause with examples and syntax. Furthermore, if have any doubt regarding CQL commands, feel free to ask in the comment section.
Related Topic – Cassandra Interview Questions
For reference

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.