+1 vote
in Databases by (59.4k points)
Can I use subqueries in Neo4j? If yes, give an example?

1 Answer

+1 vote
by (71.8k points)
selected by
Best answer

In Neo4j, you can use subqueries in the WHERE clause to perform more complex pattern filtering operations. Here's an example of how you can use a subquery in Neo4j:

MATCH (c:Compound)-[]-(p:Protein)


MATCH (c)-[r]-(d:Disease)

WHERE d.node_label CONTAINS "cancer"


RETURN p.node_id, p.node_label, p.node_definition 

In the above Cypher query, the subquery is mentioned inside WHERE EXISTS{} that selects compounds associated with cancer.

You can modify this example to fit your specific use case by changing the node labels, property names, and conditions in the subquery to match your data model and filtering requirements.

Related questions

+1 vote
1 answer
+3 votes
1 answer