I have the below 4 queries in Neo4j graphdb. How do I merge all 4 in single query and get the result instead executing 4 different query?
MATCH (n:Companies{company_id:1})-[:ATTACHED_TO]-(t:Department) return collect(distinct t) as department
MATCH (n:Companies{company_id:1}})-[:ATTACHED_TO]-(c:Section) return collect(distinct c) as section
MATCH (n:Companies{company_id:1}}) return n`;
MATCH (n:Companies{company_id:1}})-[:ATTACHED_TO]-(g:Images) return collect(distinct g) as images
Thanks....
I tried adding Department,Section,Images after ATTACHED_TO but it gives empty result.
This will do. You can assign company id:1 as a variable then use it throughout the query. OPTIONAL match will return empty when department or section or images are not attached to n.
MATCH (n:Companies{company_id:1})
OPTIONAL MATCH (n)-[:ATTACHED_TO]-(t:Department)
OPTIONAL MATCH (n)-[:ATTACHED_TO]-(c:Section)
OPTIONAL MATCH (n)-[:ATTACHED_TO]-(g:Images)
RETURN n, collect(distinct t) as department, collect(distinct c) as section, collect(distinct g) as images