cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Can I Use a command to get all result from 2 relationship.

 
1 ACCEPTED SOLUTION

Since the two queries are exactly the same except relationship type differs, you can merge them as follows:

match (p:Person)-[r:ACTED_IN|DIRECTED]->(m:Movie)
WHERE toLower(r.role) CONTAINS 'dog'
return p.name,r.role,m.title

View solution in original post

3 REPLIES 3

Dear all.
I am learning 

Intermediate Cypher Queries Course 
At Part.
Using the CONTAINS Predicate | GraphAcademy (neo4j.com)

Requirement is as forllow:
Write and execute a query to return the name of the person, their role, and the movie title where the role played by the actors or director had a value that included 'dog' (case-insensitive)? That is, the role could contain "Dog", "dog", or even "DOG".

I solve the solution by exec 2 query as follow:


match (p:Person)-[r:ACTED_IN]->(m:Movie)
WHERE toLower(r.role) CONTAINS 'dog'
return p.name,r.role,m.title

And:
MATCH (p:Person)-[r:DIRECTED]->(m:Movie)
WHERE toLower(r.role) contains 'dog'
return p.name,r.role,m.title

THen I Sum number of Row manually?
The Question is? Can I Use just one cypher command to get the result?
Thanks.

Since the two queries are exactly the same except relationship type differs, you can merge them as follows:

match (p:Person)-[r:ACTED_IN|DIRECTED]->(m:Movie)
WHERE toLower(r.role) CONTAINS 'dog'
return p.name,r.role,m.title

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online