15.7. Return

15.7.1. Return nodes
15.7.2. Return relationships
15.7.3. Return property
15.7.4. Identifier with uncommon characters
15.7.5. Column alias
15.7.6. Optional properties
15.7.7. 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.svg

15.7.1. Return nodes

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

Query

START n=node(2)
RETURN n

The node.

Result

n
1 rows, 0 ms

Node[2]{name->"B"}


15.7.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.

Result

r
1 rows, 1 ms

:KNOWS[0] {}


15.7.3. Return property

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

Query

START n=node(1)
RETURN n.name

The the value of the property name.

Result

n.name
1 rows, 0 ms

"A"


15.7.4. 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`.`<<!!__??>>`

The node indexed with name "A" is returned

Result

This isn't a common identifier.<<!!__??>>
1 rows, 0 ms

"Yes!"


15.7.5. 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 rows, 0 ms

55


15.7.6. 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?

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>


15.7.7. 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, but only once.

Result

b
1 rows, 1 ms

Node[2]{name->"B"}