Overview
The YIELD
clause can be used in the CALL
and NEXT
statements to select and rename variables to allow exposure in subsequent parts of the query.
<yield clause> ::= "YIELD" <yield item list>
<yield item list> ::= <yield item> [ { "," <yield item> }... ]
<yield item> ::= <yield item name> [ <yield item alias> ]
<yield item name> ::= <field name>
<yield item alias> ::= "AS" <binding variable>
Example Graph
The following examples run against this graph:
To create this graph, run the following query against an empty graph:
INSERT (rowlock:User {_id: 'U01', name: 'rowlock'}),
(brainy:User {_id: 'U02', name: 'Brainy'}),
(purplechalk:User {_id: 'U03', name: 'purplechalk'}),
(mochaeach:User {_id: 'U04', name: 'mochaeach'}),
(lionbower:User {_id: 'U05', name: 'lionbower'}),
(c01:Club {_id: 'C01'}),
(c02:Club {_id: 'C02'}),
(rowlock)-[:Follows]->(brainy),
(mochaeach)-[:Follows]->(brainy),
(purplechalk)-[:Follows]->(mochaeach),
(purplechalk)-[:Follows]->(lionbower),
(brainy)-[:Joins {memberNo: 1}]->(c01),
(lionbower)-[:Joins {memberNo: 2}]->(c01),
(mochaeach)-[:Joins {memberNo: 9}]->(c02)
NEXT YIELD
This query finds clubs joined by users followed by the user purplechalk
:
LET name = "purplechalk"
MATCH (:User {name: name})-[:Follows]->(u:User)
RETURN *
NEXT YIELD u
MATCH (u)-[:Joins]->(c:Club)
RETURN collect_list(c._id)
Result:
collect_list(c) |
---|
["C01","C02"] |