Following cypher does not work, Can anyone please throw some light? thanks.
MATCH (u:`user`)
WHERE ID(u)=111
MATCH (u)<-[:`manager`]-(`subordinates`)-[:`manager`]->(`subordinates.manager`)
RETURN
`subordinates.manager`
this does not return anything, I am expecting it to return the user with id 111
following cypher works,
MATCH (u:`user`)
WHERE ID(u)=111
MATCH (u)<-[:`manager`]-(`subordinates`)
MATCH (`subordinates`)-[:`manager`]->(`subordinates.manager`)
RETURN
`subordinates.manager`
you have one user and you want to find all the subordinates (actually only one level below) and from those subordinates the managers (which means there is more than one manager for some subordinates) and you want to insure the given user is in the list of the managers.
In cypher, you will query like this:
MATCH (u:user)<-[:has_manager]-(s:subordinate)
WHERE ID(u)=111
with s
MATCH (s)-[:has_manager]->(m:manager)
RETURN m.name
Pay attention that user, manager and subordinate are labels. has_manager is a relationship type. You read the whole according to the arrow direction. Therefore I change the relationship from "manager" to a verb to have it like a sentence:
(some:subordinate)-[:has_manager]->(one:manager)
and
(one:manager)<-[:has_manager]-(some:subordinate)
are exactly the same.