sohna pathak
sohna pathak

Reputation: 37

How to create a relation between two node having same node name in neo4j

I want to create a friends relation between abcd node and vbnm node having same node-name - Student neo4j graph database visualization

I execute the following query, It doesn't show me any error but this query doesn't create any relation

match(Student:Stu),(Student:Stu)where Student.name="abcd" AND Student.name="vbnm" create(Student)-[fr:friends]->(Student)

Upvotes: 0

Views: 57

Answers (2)

Tomaž Bratanič
Tomaž Bratanič

Reputation: 6514

I think you are confused by the syntax a little bit. Let me give you an example of a MATCH query syntax.

MATCH (variable1:Label),(variable2:Label) where variable1.foo = variable2.foo

You mixed label and variable in your query and each entity should have its own variable (variable1 and variable2) so you can interact with them. So in your case the optimal query looks something like:

MATCH (s1:Student),(s2:Student ) where s1.name="abcd" AND s2.name="vbnm" 
CREATE (s1)-[:friends]->(s2)

Note that you do not need to assign a variable to [:friends] relationship as you do not interact with it later in the same query.

Upvotes: 0

stdob--
stdob--

Reputation: 29172

You need use different variable name:

match(Student1:Stu),(Student2:Stu)
where Student1.name="abcd" AND 
            Student2.name="vbnm" 
create(Student1)-[fr:friends]->(Student2)

Upvotes: 1

Related Questions