Neo4j CQL - IN Operator



Like SQL, Neo4j CQL has provided an IN operator to give a collection of values to CQL Commands.

IN Operator syntax

IN[<Collection-of-values>]

Syntax Description

S.No.Syntax ElementDescription
1.INIt is a Neo4j CQL keyword.
2.[It tells Neo4j CQL that the start of a collection of values.
3.]It tells Neo4j CQL that the end of a collection of values.
4.<Collection-of-values>It is a collection of values separated by comma operator.

Let us examine this with an example.

Example

This example demonstrates how to use IN operator to retrieve Employee node details.

Step 1 - Open Neo4j Data Browser

Neo4j CQL Tutorial

Step 2 - Type the below command at dollar prompt in Data Browser.

MATCH (e:Employee) 
RETURN e.id,e.name,e.sal,e.deptno
Neo4j CQL Tutorial

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

Neo4j CQL Tutorial

We can observe that this query returns 4 rows.

Step 4 - Type the below command and click on Execute button.

MATCH (e:Employee) 
WHERE e.id IN [123,124]
RETURN e.id,e.name,e.sal,e.deptno
Neo4j CQL Tutorial

This query returns only two rows whose ids are matched specified in the IN operator.

Advertisements