The RETURN clause is used go back nodes, relationships, and properties in Neo4j. In this bankruptcy, we're going to learn how to −
- Return nodes
- Return a couple of nodes
- Return relationships
- Return properties
- Return all factors
- Return a variable with column alias
Returning Nodes
You can go back a node the use of the RETURN clause.
Syntax
Following is a syntax to go back nodes the use of the RETURN clause.
Create (node:label {properties})
RETURN node
Example
Before proceeding with the example, create three nodes and a pair of relationships as proven under.
Create (Dhoni:player {name: "MahendraSingh Dhoni", YOB: 1981, POB: "Ranchi"})
CREATE (Ind:Country {name: "India", result: "Winners"})
CREATE (CT2013:Tornament {name: "ICC Champions Trophy 2013"})
CREATE (Ind)-[r1:WINNERS_OF {NRR:0.938 ,pts:6}]->(CT2013)
CREATE(Dhoni)-[r2:CAPTAIN_OF]->(Ind)
Following is a sample Cypher Query which creates a node named Dhoni and returns it.
Create (Dhoni:player {name: "MahendraSingh Dhoni", YOB: 1981, POB: "Ranchi"})
RETURN Dhoni
To execute the above question, perform the subsequent steps −
Step 1 − Open the Neo4j computing device App and begin the Neo4j Server. Open the integrated browser app of Neo4j the usage of the URL http://localhost:7474/ as proven in the following screenshot.
Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted within the following screenshot.
Result
On executing, you will get the following end result.
Returning Multiple Nodes
You also can go back more than one nodes the usage of the go back clause.
Syntax
Following is the syntax to go back multiple nodes the use of the go back clause.
CREATE (Ind:Country {name: "India", result: "Winners"})
CREATE (CT2013:Tornament {name: "ICC Champions Trophy 2013"})
RETURN Ind, CT2013
Example
Following is a sample Cypher Query to return a couple of nodes the usage of the go back clause.
CREATE (Ind:Country {name: "India", result: "Winners"})
CREATE (CT2013:Tornament {name: "ICC Champions Trophy 2013"})
RETURN Ind, CT2013
To execute the above query, perform the subsequent steps −
Step 1 − Open the Neo4j desktop App and begin the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as proven in the following screenshot.
Step 2 − Copy and paste the preferred query inside the greenback set off and press the play button (to execute the question) highlighted within the following screenshot.
Result
On executing, you may get the following result. Here you could look at that Neo4j back 2 nodes.
Returning Relationships
You also can go back relationships the use of the Return clause.
Syntax
Following is the syntax to return relationships using the RETURN clause.
CREATE (node1)-[Relationship:Relationship_type]->(node2)
RETURN Relationship
Example
Following is a sample Cypher Query which creates two relationships and returns them.
CREATE (Ind)-[r1:WINNERS_OF {NRR:0.938 ,pts:6}]->(CT2013)
CREATE(Dhoni)-[r2:CAPTAIN_OF]->(Ind)
RETURN r1, r2
To execute the above query, perform the following steps −
Step 1 − Open the Neo4j computing device App and begin the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as proven in the following screenshot.
Step 2 − Copy and paste the preferred question inside the dollar prompt and press the play button (to execute the query) highlighted in the following screenshot.
Result
On executing, you may get the following result.
Returning Properties
You can also return residences the usage of the RETURN clause.
Syntax
Following is a syntax to return properties using the RETURN clause.
Match (node:label {properties . . . . . . . . . . })
Return node.property
Example
Following is a sample Cypher Query to return the homes of a node.
Match (Dhoni:player {name: "MahendraSingh Dhoni", YOB: 1981, POB: "Ranchi"})
Return Dhoni.name, Dhoni.POB
To execute the above question, carry out the following steps −
Step 1 − Open the Neo4j laptop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown inside the following screenshot.
Step 2 − Copy and paste the desired question within the dollar activate and press the play button (to execute the query) highlighted in the following screenshot.
Result
On executing, you may get the following result.
Returning All Elements
You can go back all of the factors inside the Neo4j database the use of the RETURN clause.
Example
Following is an example Cypher Query to return all of the factors inside the database.
Match p = (n {name: "India", result: "Winners"})-[r]-(x)
RETURN *
To execute the above question, perform the following steps −
Step 1 − Open the Neo4j computing device App and start the Neo4j Server. Open the integrated browser app of Neo4j the usage of the URL http://localhost:7474/ as shown inside the following screenshot.
Step 2 − Copy and paste the favored query inside the dollar prompt and press the play button (to execute the question) highlighted in the following screenshot.
Result
On executing, you will get the subsequent result.
Returning a Variable With a Column Alias
You can return a selected column with alias using RETURN clause in Neo4j.
Example
Following is a sample Cypher Query which returns the column POB as Place Of Birth.
Match (Dhoni:player {name: "MahendraSingh Dhoni", YOB: 1981, POB: "Ranchi"})
Return Dhoni.POB as Place Of Birth
To execute the above query, carry out the subsequent steps −
Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j the usage of the URL http://localhost:7474/ as shown in the following screenshot.
Step 2 − Copy and paste the preferred question within the dollar prompt and press the play button (to execute the question) highlighted inside the following screenshot.
Result
On executing, you will get the following end result.