How to Limit returned rows in Cassandra Query Language
You can use LIMIT option in query to control the number of rows you want to get.
Syntax:
column2,
...FROM tablename LIMIT numberofrow;
Example:
Let's create employee table by using below CQL Statement.
(
employeeid INT ,
fname TEXT,
lname TEXT,
address TEXT,
age TINYINT,
PRIMARY KEY((employeeid,fname),lname)
)
WITH clustering
ORDER BY (
lname DESC);
Insert sample data by using CQL insert statement
(employeeid,fname,lname,address,age)
VALUES (1,'John','Doe','ABC Address',23);
INSERT INTO employee
(employeeid,fname,lname,address,age)
VALUES (2,'Robert','Ladson',' Address',40);
INSERT INTO employee
(employeeid,fname,lname,address,age)
VALUES (3,'M','Raza','New Address',38);
INSERT INTO employee
(employeeid,fname,lname,address,age)
VALUES (3,'M','Ali','New Address',38);
Now if we want to get only 2 records then we can use below statement. Cassandra is going to return first 2 records.
FROM employee LIMIT 2;
Output
employeeid | fname | lname | address | age
------------+-------+-------+-------------+-----
3 | M | Raza | New Address | 38
3 | M | Ali | New Address | 38
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.