hilbert
hilbert

Reputation: 266

understanding cypher output

I have a graph like this: (2)<-[0:CHILD]-(1)-[1:CHILD]->(3) In words: Node 1,2 and 3 (all with names); Edges 0 and 1

I write the following cypher-query:

START nodes = node(1,2,3), relationship = relationship(0,1) 
RETURN nodes, relationship

and got as a result:

==> +-----------------------------------------------+
==> | nodes                          | relationship |
==> +-----------------------------------------------+
==> | Node[1]{name->"Risikogruppe2"} | :CHILD[0] {} |
==> | Node[1]{name->"Risikogruppe2"} | :CHILD[1] {} |
==> | Node[2]{name->"Beruf 1"}       | :CHILD[0] {} |
==> | Node[2]{name->"Beruf 1"}       | :CHILD[1] {} |
==> | Node[3]{name->"Beruf 2"}       | :CHILD[0] {} |
==> | Node[3]{name->"Beruf 2"}       | :CHILD[1] {} |
==> +-----------------------------------------------+
==> 6 rows, 0 ms

now my question: why I became all nodes twice and relationships three time? I just want to get all of it one time.

thanks for your time ^^

Upvotes: 0

Views: 286

Answers (2)

Eve Freeman
Eve Freeman

Reputation: 33155

The way Cypher works is very similar to SQL. When you create your variables in your START clause, you're sort of doing a from nodes, relationships in SQL (tables). The reason you're getting a cartesian product of all of the possible values for the two, is because you're not doing any sort of match or where to filter them, so it's basically like:

select *
from nodes, relationships

Where you forgot to put the foreign key relationship between the tables.

In Cypher, you do this by doing a match, usually:

start n=node(1,2,3), r=relationship(0,1)
match n-[r]-m // find where the n nodes and the r relationships point (to m)
return *

But since you have no match, you get a cartesian product.

Upvotes: 1

Andres
Andres

Reputation: 1454

You should only see the nodes and relationships once, unless you do some matching.

Tried to reproduce your problem, but I haven't been able to.

http://tinyurl.com/cobd8oq

Is it possible for you to create an console.neo4j.org example of your problem?

Thanks,

Andrés

Upvotes: 0

Related Questions