skip to Main Content

I have a graph for cities with 6 cities, and only two of them have a relationship between them. I would like to write a query that gives me all the cities along with all the relationships in between them.

MATCH (n) RETURN n

The query above only gives me the nodes and not the relationships.
If I would like to have all the nodes along with all the relationships, what query may I use?
The query only outputs the nodes

I do have relationships as well

2

Answers


  1. you can try the below query

    MATCH (n)-[r]-()
    RETURN n, r
    

    here "-[r]-()" matches all the relationships in the graph.

    let me know if this helps.

    Login or Signup to reply.
  2. You can use the RIGHT JOIN clause, just like this:

    SELECT * FROM cypher('cities', $$ 
        MATCH (V)-[R]-(U) 
        RETURN V,R,U $$) AS g1(V agtype, R agtype, U agtype)
        RIGHT JOIN cypher('cities', $$
        MATCH (V) 
        RETURN V $$) AS g2(V agtype) 
        ON g1.V= g2.V;
    

    In your case, it will show you this:
    a graph with all nodes, including those that have no relationship

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search