cancel
Showing results for 
Search instead for 
Did you mean: 

SELECT ONE NODE, WHEN MULTIPLE NODES ARE RELATED TO A SINGLE NODe

karora7190
Node Clone

I have the following Graph where Nodes can be connected like this :

I Need to write a query so that I get either A or B as an output.

Thanks in advance for the help.

4 REPLIES 4

tard_gabriel
Ninja
Ninja

Not sure what you really want, we would need more information about your domain ( what's the labels, properties of your nodes etc. ) to better fits your need.

But here is a general answer for your case:

MATCH (n1)-[:COPY_OF]->(n2)
RETURN n1

Since it's a really basic query I would highly suggest to read a lot more about Cypher.
There is a basic course.

You can enroll on each part of this course by clicking one of the 5 parts with the proposed order.

HI @tard.gabriel ,

Thanks a lot for your reply.
The query that you are proposing will return both A and B.
I want to either A or B as an output and not both.

karora7190
Node Clone

TO Add more to the use cases. Here is the scenario :
I have n master questions.
When I create a Survey I have two options I can create a fresh question or can create a copy of these master questions.
Now, Suppose if the user creates two questions with the same master question.
I don't want the responder to see both questions(as they are a copy) I want them to see either 1.

Hopefully this helps.

tard_gabriel
Ninja
Ninja

As there is not enough information about your model ( like @karora7190 said ) to chose one of them based on any criteria you can do this as a general answer:

MATCH (n1)-[:COPY_OF]->(n2)
RETURN n1 LIMIT 1

A empty model get an empty answer, give a soul or context to your question.
A graph and questions related to it is useless without a soul or context.