Selecting a list of nodes through multiple path addresses in Cypher

Viewed 2159

Consider following Cyphers:

MATCH (n{name: "John"})-[:Colleague]-(m) RETURN m;

This query finds Colleague(s) of John(s). Now another one:

MATCH (n{name: "John"})-[:Friend]-()-[:Colleague]-(m) RETURN m;

This one finds Colleague(s) of John(s)' Friend(s). And now the last one:

MATCH (n{name: "John"})-[:Colleague]-()-[:Friend]-(m) RETURN m;

Finally, this one finds Friend(s) of John(s)' Colleague(s). What I'm looking for is a Cypher query which finds the union of all of the nodes found by the given queries.

Please note that this is just an example. What I'm actually asking here is how to find one set of nodes using multiple paths? Something like:

MATCH (n{name: "John"})
    -[:Colleague]- /
    -[:Friend]-()-[:Colleague]- /
    -[:Colleague]-()-[:Friend]-
    (m) RETURN m;
5 Answers
Related