15.12. Return

15.12.1. Return nodes
15.12.2. Return relationships
15.12.3. Return property
15.12.4. Return all elements
15.12.5. Identifier with uncommon characters
15.12.6. Column alias
15.12.7. Optional properties
15.12.8. Unique results

In the RETURN part of your query, you define which parts of the pattern you are interested in. It can be nodes, relationships, or properties on these.

Graph

cypher-return-graph.txt.svg

15.12.1. Return nodes

To return a node, list it in the RETURN statemenet.

Query

START n=node(2)
RETURN n

The example will return the node.

Result

n
1 row
0 ms

Node[2]{name:"B"}


Try this query live. (1) {"age":55,"happy":"Yes!","name":"A"} (2) {"name":"B"} (1)-[:KNOWS]->(2) {} (1)-[:BLOCKS]->(2) {} start n=node(2) return n

15.12.2. Return relationships

To return a relationship, just include it in the RETURN list.

Query

START n=node(1)
MATCH (n)-[r:KNOWS]->(c)
RETURN r

The relationship is returned by the example.

Result

r
1 row
0 ms

:KNOWS[0] {}


Try this query live. (1) {"age":55,"happy":"Yes!","name":"A"} (2) {"name":"B"} (1)-[:KNOWS]->(2) {} (1)-[:BLOCKS]->(2) {} start n=node(1) match (n)-[r:KNOWS]->(c) return r

15.12.3. Return property

To return a property, use the dot separator, like this:

Query

START n=node(1)
RETURN n.name

The value of the property name gets returned.

Result

n.name
1 row
0 ms

"A"


Try this query live. (1) {"age":55,"happy":"Yes!","name":"A"} (2) {"name":"B"} (1)-[:KNOWS]->(2) {} (1)-[:BLOCKS]->(2) {} start n=node(1) return n.name

15.12.4. Return all elements

When you want to return all nodes, relationships and paths found in a query, you can use the * symbol.

Query

START a=node(1)
MATCH p=a-[r]->b
RETURN *

This returns the two nodes, the relationship and the path used in the query.

Result

abrp
2 rows
0 ms

Node[1]{name:"A",happy:"Yes!",age:55}

Node[2]{name:"B"}

:KNOWS[0] {}

[Node[1]{name:"A",happy:"Yes!",age:55},:KNOWS[0] {},Node[2]{name:"B"}]

Node[1]{name:"A",happy:"Yes!",age:55}

Node[2]{name:"B"}

:BLOCKS[1] {}

[Node[1]{name:"A",happy:"Yes!",age:55},:BLOCKS[1] {},Node[2]{name:"B"}]


Try this query live. (1) {"age":55,"happy":"Yes!","name":"A"} (2) {"name":"B"} (1)-[:KNOWS]->(2) {} (1)-[:BLOCKS]->(2) {} start a=node(1) match p=a-[r]->b return *

15.12.5. Identifier with uncommon characters

To introduce a placeholder that is made up of characters that are outside of the english alphabet, you can use the ` to enclose the identifier, like this:

Query

START `This isn't a common identifier`=node(1)
RETURN `This isn't a common identifier`.happy

The node indexed with name "A" is returned

Result

This isn't a common identifier.happy
1 row
0 ms

"Yes!"


Try this query live. (1) {"age":55,"happy":"Yes!","name":"A"} (2) {"name":"B"} (1)-[:KNOWS]->(2) {} (1)-[:BLOCKS]->(2) {} start `This isn't a common identifier`=node(1) return `This isn't a common identifier`.happy

15.12.6. Column alias

If the name of the column should be different from the expression used, you can rename it by using AS <new name>.

Query

START a=node(1)
RETURN a.age AS SomethingTotallyDifferent

Returns the age property of a node, but renames the column.

Result

SomethingTotallyDifferent
1 row
0 ms

55


Try this query live. (1) {"age":55,"happy":"Yes!","name":"A"} (2) {"name":"B"} (1)-[:KNOWS]->(2) {} (1)-[:BLOCKS]->(2) {} start a=node(1) return a.age AS SomethingTotallyDifferent

15.12.7. Optional properties

If a property might or might not be there, you can select it optionally by adding a questionmark to the identifier, like this:

Query

START n=node(1, 2)
RETURN n.age?

This example returns the age when the node has that property, or null if the property is not there.

Result

n.age?
2 rows
0 ms

55

<null>


Try this query live. (1) {"age":55,"happy":"Yes!","name":"A"} (2) {"name":"B"} (1)-[:KNOWS]->(2) {} (1)-[:BLOCKS]->(2) {} start n=node(1, 2) return n.age?

15.12.8. Unique results

DISTINCT retrieves only unique rows depending on the columns that have been selected to output.

Query

START a=node(1)
MATCH (a)-->(b)
RETURN distinct b

The node named B is returned by the query, but only once.

Result

b
1 row
0 ms

Node[2]{name:"B"}


Try this query live. (1) {"age":55,"happy":"Yes!","name":"A"} (2) {"name":"B"} (1)-[:KNOWS]->(2) {} (1)-[:BLOCKS]->(2) {} start a=node(1) match (a)-->(b) return distinct b