Hello,
I'm starting with Neo4J. For a given node I want to list Outgoing & Incoming relationships.
I do this :
// List Outgoing & Incoming relations for a node
// Outgoing
MATCH (s)-[r]->(t)
WHERE s.name = 'f4b1'
RETURN t.name , 'Out' as `relations`
UNION ALL
// Incoming
MATCH (t)<-[r]-(s)
WHERE t.name = 'f4b1'
RETURN t.name , 'In' as `relations`
Example based on the movies dataset without the need for a JOIN:
MATCH (p:Person {name: "Jessica Thompson"})-[r]-(o)
RETURN p.name
, p = endNode(r) as isIncoming
, type(r) as relationType
, coalesce(o.name, o.title) as other
MATCH (s) // you should really use labels here, and create an index to support fast lookup by property
WHERE s.name = 'f4b1'
RETURN [(s)<--(t) | t.name] as In, [(s)-->(t) | t.name] as Out