Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-21-2021 12:01 PM
I have a search query for a property which can be achieved by the following cypher query
MATCH (n: USER) WHERE n.fullname CONTAINS 'q' RETURN n
Say it matches 3 USER nodes and returns those 3
Then I want to see if there is a relationship with those nodes which is achieved by the following query which is handled by a for loop in python
MATCH (n: USER{userid: 'U1'})-[r:FOLLOWING]->(m:USER{userid: 'RESULT_USERID'}) RETURN m
(Executed 3 times for 3 results)
I want to do both of this in single query. How can it be achieved?
Thanks,
Skanda
08-21-2021 08:38 PM
Hi Skanda,
You can easily achieve this using 'WITH' to carry forward the result from the first query and use it into the second query.
Something like this-
MATCH (n: USER) WHERE n.fullname CONTAINS 'q'
WITH n
MATCH (n)-[r:FOLLOWING]->(m:USER{userid: 'RESULT_USERID'}) RETURN m;
This would show the same result as you expect under this one singe query.
08-23-2021 09:55 AM
Perfect! Thanks for your quick inputs Dhurv.
All the sessions of the conference are now available online