I am having 2 nodes lets say of 2 type 'Student' and 'Class'
Student have {id, name}.
Class have {id, name}.
Student can have optional relationship with Class node as 'ATTENDS'.
(s:Student)-[r:ATTENDS]->(c:Class).
[r:ATTENDS] - Optional relationship. (present or may not present)
I want student record as it's all properties. If present relationship then class_name will match with present "Class" node else class_name will be null.
{student_id,student_name,class_name}
I tried by cypher query, but not getting result. Please help.
OPTIONAL MATCH (s:Student)-[:ATTENDS]->(c:Class) WHERE s.id =1
RETURN s.id AS student_id , s.name as student_name, c.name as class_name
By this query, if relationship exists then all values, if no relationship exists then all values are null.