Neo4j CQL - LIMIT & SKIP Clauses



Neo4j CQL LIMIT clause

Neo4j CQL has provided "LIMIT" Clause to filter or limit the number of rows return by a query. It trims the results from the bottom of the CQL Query Result Set.

If we want to trim the results from the top of the CQL Query Result set, then we should go for CQL SKIP clause. Please refer next section of this chapter for CQL SKIP clause

LIMIT clause syntax

LIMIT <number>

Syntax Description

S.No.Syntax ElementDescription
1.LIMITIt is a Neo4j CQL keyword.
2.<number>It is an inter value.

Example

This example demonstrates how to use CQL LIMIT clause to reduce the number of records return by a MATCH + RETURN Query.

Step 1 - Open Neo4j Data Browser

Neo4j CQL Tutorial

It is Neo4j Data Browser Homepage

Step 2 - Type the below command on Data Browser without LIMIT clause

MATCH (emp:Employee) 
RETURN emp
Neo4j CQL Tutorial

Step 3 - Click on "Execute" button and observe the results.

Neo4j CQL Tutorial

It returns total number of results available in the database: 4 records

Step 4 - Type the below command on Data Browser with LIMIT clause

MATCH (emp:Employee) 
RETURN emp
LIMIT 2
Neo4j CQL Tutorial

Step 5 - Click on "Execute" button and observe the results.

Neo4j CQL Tutorial

It returns only two results from Top as we have defined limit = 2. That means first two rows.

Neo4j CQL SKIP clause

Neo4j CQL has provided "SKIP" Clause to filter or limit the number of rows return by a query. It trims the results from the top of the CQL Query Result Set.

If we want to trim the results from the bottom of the CQL Query Result set, then we should go for CQL LIMIT clause. Please refer above section of this chapter for CQL LIMIT clause

SKIP clause syntax:

SKIP <number>

Syntax Description

S.No.Syntax ElementDescription
1.SKIPIt is a Neo4j CQL keyword.
2.<number>It is an inter value.

Example

This example demonstrates how to use CQL SKIP clause to reduce the number of records return by a MATCH + RETURN Query.

Step 1 - Open Neo4j Data Browser

Step 2 - Type the below command on Data Browser without SKIP clause

MATCH (emp:Employee) 
RETURN emp
Neo4j CQL Tutorial

Step 3 - Click on "Execute" button and observe the results.

Neo4j CQL Tutorial

It returns total number of results available in the database: 4 records

Step 4 - Type the below command on Data Browser with SKIP clause

MATCH (emp:Employee) 
RETURN emp
SKIP 2
Neo4j CQL Tutorial

Step 5 - Click on "Execute" button and observe the results.

Neo4j CQL Tutorial

It returns only two results from Bottom as we have defined skip = 2. That means last two rows.

Advertisements