nvqhuy14
(Nvqhuy14)
1
Hi folks,
I am attempting to extract a subgraph from my graph database.
Subgraph structure like:
User -- WATCHED --> Resource
Resource -- CONTAINS --> Video
Course -- HAS_RESOURCE --> Resource
This is cypher code to extract User
, Resource
and Video
, but now I don't know how to extract Course
more
MATCH (u:User)-[w:WATCHED]->(r:Resource)-[:CONTAINS]->(v:Video)
RETURN * LIMIT 50
Please help me, I want to extract all 4 node labels: User
, Resource
, Video
and Course
you can use a query containing a second MATCH with the variable r, to match related courses
create (:User)-[:WATCHED]->(r:Resource)-[:CONTAINS]->(:Video)
create (:Course)-[:HAS_RESOURCE]->(r);
match (u:User)-[w:WATCHED]->(r:Resource)-[:CONTAINS]->(v:Video)
match (c:Course)-[:HAS_RESOURCE]->(r)
return u,r,v,c
update: actually in this case you can write the read query like this
match (u:User)-[w:WATCHED]->(r:Resource)-[:CONTAINS]->(v:Video), (c:Course)-[:HAS_RESOURCE]->(r)
return u,r,v,c
in this case, it does not make any difference
about when the coma syntax makes a difference with the two MATCH one
see this https://twitter.com/adamcowley/status/1663522447168090114
1 Like
nvqhuy14
(Nvqhuy14)
3
I solved it. Thank you so much