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

1 Answer

+1 vote
by (59.1k 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.